diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index a4dcf3ad3..ad803db67 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -7287,8 +7287,10 @@ int wc_RsaKeyToDer(RsaKey* key, byte* output, word32 inLen) seqSz = SetSequence(verSz + intTotalLen, seq); outLen = seqSz + verSz + intTotalLen; - if (outLen > (int)inLen) + if (outLen > (int)inLen) { + FreeTmpRsas(tmps, key->heap); return BAD_FUNC_ARG; + } /* write to output */ XMEMCPY(output, seq, seqSz);