From 32ed4735d21f6e57e4f6664b8155b25079ca4047 Mon Sep 17 00:00:00 2001 From: David Garske Date: Tue, 24 Sep 2024 17:01:42 -0700 Subject: [PATCH] Resolve hash new leak due to improper heap hint check. Make sure isAllocated is initialized to 0. --- wolfcrypt/src/hash.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/wolfcrypt/src/hash.c b/wolfcrypt/src/hash.c index d5988341d7..5c9d3ff1e4 100644 --- a/wolfcrypt/src/hash.c +++ b/wolfcrypt/src/hash.c @@ -710,6 +710,7 @@ int wc_HashInit_ex(wc_HashAlg* hash, enum wc_HashType type, void* heap, if (hash == NULL) return BAD_FUNC_ARG; + hash->isAllocated = 0; switch (type) { case WC_HASH_TYPE_MD5: #ifndef NO_MD5 @@ -1146,8 +1147,9 @@ int wc_HashFree(wc_HashAlg* hash, enum wc_HashType type) ret = BAD_FUNC_ARG; }; - if (isAllocated && heap) + if (isAllocated) { XFREE(hash, heap, DYNAMIC_TYPE_HASHES); + } return ret; }