]> 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:42:15 +0000 (16:42 +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)

(cherry picked from commit e8deb32af4874c781838c1596c6355712b5d0ed0)

test/evp_test.c

index 86b8198643aee43de25f9a046662cec0a17f9404..3085863a6ef8117d4280e062f4a91cf9943b1ae8 100644 (file)
@@ -352,8 +352,10 @@ static int digest_test_init(EVP_TEST *t, const char *alg)
     if ((digest = fetched_digest = EVP_MD_fetch(libctx, alg, NULL)) == 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;