From 476355b5bfcba96deb37d280330b7386d86341f8 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Thu, 14 Jan 2016 23:58:30 -0700 Subject: [PATCH] fix potential memory leak on fail --- wolfcrypt/src/rsa.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wolfcrypt/src/rsa.c b/wolfcrypt/src/rsa.c index dac9224c3..6b165638f 100644 --- a/wolfcrypt/src/rsa.c +++ b/wolfcrypt/src/rsa.c @@ -278,6 +278,10 @@ static int wc_MGF1(int hType, byte* seed, word32 seedSz, /* hash and append to existing output */ if ((ret = wc_Hash(hType, tmp, (seedSz + 4), tmp, tmpSz)) != 0) { + /* check for if dynamic memory was needed, then free */ + if (tmpF) { + XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER); + } return ret; } @@ -381,6 +385,7 @@ static int wc_RsaPad_OAEP(const byte* input, word32 inputLen, byte* pkcsBlock, } seed = (byte*)XMALLOC(hLen, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (seed == NULL) { + XFREE(lHash, NULL, DYNAMIC_TYPE_TMP_BUFFER); return MEMORY_E; } #else