diff --git a/wolfcrypt/src/pkcs7.c b/wolfcrypt/src/pkcs7.c index af6bb55bd..a24d6a271 100644 --- a/wolfcrypt/src/pkcs7.c +++ b/wolfcrypt/src/pkcs7.c @@ -11489,8 +11489,13 @@ int wc_PKCS7_EncodeAuthEnvelopedData(PKCS7* pkcs7, byte* output, return MEMORY_E; } - FlattenAttributes(pkcs7, flatAuthAttribs, authAttribs, + ret = FlattenAttributes(pkcs7, flatAuthAttribs, authAttribs, authAttribsCount); + if (ret != 0) { + wc_PKCS7_FreeEncodedRecipientSet(pkcs7); + XFREE(flatAuthAttribs, pkcs7->heap, DYNAMIC_TYPE_PKCS7); + return ret; + } authAttribsSetSz = SetImplicit(ASN_SET, 1, authAttribsSz, authAttribSet);