From de1ee91863ea2c375c023a2aeaa87d3c8b0aface Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 17 Nov 2016 09:24:56 -0800 Subject: [PATCH 1/2] Fix memory leak issue with WOLFSSL_SMALL_STACK defined and using TI hardware accelerated hashing. --- wolfcrypt/src/port/ti/ti-hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wolfcrypt/src/port/ti/ti-hash.c b/wolfcrypt/src/port/ti/ti-hash.c index 7ca795b91..cb096ebe6 100644 --- a/wolfcrypt/src/port/ti/ti-hash.c +++ b/wolfcrypt/src/port/ti/ti-hash.c @@ -146,7 +146,7 @@ static int hashHash(const byte* data, word32 len, byte* hash, word32 algo, word3 } #ifdef WOLFSSL_SMALL_STACK - XFREE(hash, NULL, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(hash_desc, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; From b01952ea4057fabfd902a83681226d10869eda05 Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 17 Nov 2016 09:34:31 -0800 Subject: [PATCH 2/2] Cleanup the hash free in FreeHandshakeResources. --- src/internal.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/internal.c b/src/internal.c index 02374e2dc..ec1efb283 100644 --- a/src/internal.c +++ b/src/internal.c @@ -3755,30 +3755,19 @@ void SSL_ResourceFree(WOLFSSL* ssl) #endif /* WOLFSSL_STATIC_MEMORY */ } -#ifdef WOLFSSL_TI_HASH -static void HashFinal(WOLFSSL * ssl) { - byte dummyHash[32] ; -#ifndef NO_MD5 - wc_Md5Final(&(ssl->hsHashes->hashMd5), dummyHash) ; -#endif -#ifndef NO_SHA - wc_ShaFinal(&(ssl->hsHashes->hashSha), dummyHash) ; -#endif -#ifndef NO_SHA256 - wc_Sha256Final(&(ssl->hsHashes->hashSha256), dummyHash) ; -#endif -} -#else - - #define HashFinal(ssl) - -#endif /* WOLFSSL_TI_HASH */ - /* Free any handshake resources no longer needed */ void FreeHandshakeResources(WOLFSSL* ssl) { +#ifndef NO_MD5 + wc_Md5Free(&ssl->hsHashes->hashMd5); +#endif +#ifndef NO_SHA + wc_ShaFree(&ssl->hsHashes->hashSha); +#endif +#ifndef NO_SHA256 + wc_Sha256Free(&ssl->hsHashes->hashSha25); +#endif - HashFinal(ssl) ; #ifdef HAVE_SECURE_RENEGOTIATION if (ssl->secure_renegotiation && ssl->secure_renegotiation->enabled) { WOLFSSL_MSG("Secure Renegotiation needs to retain handshake resources");