]> 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:55 +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)

(cherry picked from commit e8deb32af4874c781838c1596c6355712b5d0ed0)

test/evp_test.c

index 08abdf3648eec0bf48e6714438a1b1c14426c077..3bf8e4ddf9e3ffac3e8a9bceecaf612072ffd3ba 100644 (file)
@@ -675,8 +675,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;