From: Jiasheng Jiang Date: Mon, 11 Aug 2025 21:52:59 +0000 (+0000) Subject: test/ml_kem_internal_test.c: Add EVP_MD_free() in the error path to avoid memory... X-Git-Tag: openssl-3.5.3~65 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=eea39c1a81162189c12f92af9c86cf5cfe052ce0;p=thirdparty%2Fopenssl.git 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) --- diff --git a/test/ml_kem_internal_test.c b/test/ml_kem_internal_test.c index bb745a2afc1..c8c4cdf6f4d 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; }