From eea39c1a81162189c12f92af9c86cf5cfe052ce0 Mon Sep 17 00:00:00 2001 From: Jiasheng Jiang Date: Mon, 11 Aug 2025 21:52:59 +0000 Subject: [PATCH] test/ml_kem_internal_test.c: Add EVP_MD_free() in the error path to avoid memory leak Add EVP_MD_free() to free sha256 in the error path to avoid memory leak. Fixes: d2136d9 ("Multi-variant ML-KEM") Signed-off-by: Jiasheng Jiang Reviewed-by: Shane Lontis Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/27946) (cherry picked from commit d6fcaa5658bca18474a5e55d7c4807efcc242173) --- test/ml_kem_internal_test.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/ml_kem_internal_test.c b/test/ml_kem_internal_test.c index bb745a2afc..c8c4cdf6f4 100644 --- a/test/ml_kem_internal_test.c +++ b/test/ml_kem_internal_test.c @@ -107,8 +107,10 @@ static int sanity_test(void) return 0; if (!TEST_ptr(privctx = RAND_get0_private(NULL)) - || !TEST_ptr(pubctx = RAND_get0_public(NULL))) - return 0; + || !TEST_ptr(pubctx = RAND_get0_public(NULL))) { + ret = -1; + goto err; + } decap_entropy = ml_kem_public_entropy + ML_KEM_RANDOM_BYTES; @@ -134,8 +136,10 @@ static int sanity_test(void) params[1] = OSSL_PARAM_construct_uint(OSSL_RAND_PARAM_STRENGTH, &strength); params[2] = OSSL_PARAM_construct_end(); - if (!TEST_true(EVP_RAND_CTX_set_params(privctx, params))) - return 0; + if (!TEST_true(EVP_RAND_CTX_set_params(privctx, params))) { + ret = -1; + goto err; + } public_key = ossl_ml_kem_key_new(NULL, NULL, alg[i]); private_key = ossl_ml_kem_key_new(NULL, NULL, alg[i]); @@ -254,6 +258,8 @@ static int sanity_test(void) OPENSSL_free(encoded_public_key); OPENSSL_free(ciphertext); } + +err: EVP_MD_free(sha256); return ret == 0; } -- 2.47.2