diff --git a/skeletons/OCTET_STRING.c b/skeletons/OCTET_STRING.c
index 16d3a8958d82d85bae66a568d41e0f228ef4086e..89d5de0b4157d4f53d91e60f050b93324f87c34f 100644
--- a/skeletons/OCTET_STRING.c
+++ b/skeletons/OCTET_STRING.c
@@ -1109,9 +1109,12 @@ OCTET_STRING__decode_xer(asn_codec_ctx_t *opt_codec_ctx,
 	 * Create the string if does not exist.
 	 */
 	if(!*sptr) {
-		*sptr = CALLOC(1, specs->struct_size);
-		if(*sptr == NULL) {
+		OCTET_STRING_t *st;
+		(void *)st = *sptr = CALLOC(1, specs->struct_size);
+		if(st) st->buf = (uint8_t *)CALLOC(1, 1);
+		if(!*sptr || !st->buf) {
 			asn_dec_rval_t rval;
+			if(*sptr) FREEMEM(*sptr);
 			rval.code = RC_FAIL;
 			rval.consumed = 0;
 			return rval;