]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
test/evp_test.c: Free fetched_digest on error to avoid memory leak
authorJiashengJiang <jiasheng@purdue.edu>
Sat, 17 May 2025 00:20:47 +0000 (20:20 -0400)
committerTomas Mraz <tomas@openssl.org>
Thu, 29 May 2025 14:41:37 +0000 (16:41 +0200)
Call EVP_MD_free() to release fetched_digest if OPENSSL_zalloc() fails, preventing a memory leak.

Fixes: 2208ba56eb ("evp_test: Add the missing check after calling OPENSSL_malloc")
Signed-off-by: JiashengJiang <jiasheng@purdue.edu>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27648)

test/evp_test.c

index cda938f1eab537fdab03ac5fc4aa509f573512d6..df30982c23a09a1b057c40082d8dcfff5a2a07a1 100644 (file)
@@ -702,8 +702,10 @@ static int digest_test_init(EVP_TEST *t, const char *alg)
     if ((digest = fetched_digest = EVP_MD_fetch(libctx, alg, propquery)) == NULL
         && (digest = EVP_get_digestbyname(alg)) == NULL)
         return 0;
-    if (!TEST_ptr(mdat = OPENSSL_zalloc(sizeof(*mdat))))
+    if (!TEST_ptr(mdat = OPENSSL_zalloc(sizeof(*mdat)))) {
+        EVP_MD_free(fetched_digest);
         return 0;
+    }
     t->data = mdat;
     mdat->digest = digest;
     mdat->fetched_digest = fetched_digest;