Commit 2ad09ef413 for openssl.org
commit 2ad09ef41396c22ade94a2cd3257843f0439b044
Author: Jiasheng Jiang <jiashengjiangcool@gmail.com>
Date: Wed Jun 25 19:22:30 2025 +0000
test/bio_pw_callback_test.c: Add BIO_free() to avoid memory leak
Add BIO_free() if PEM_read_bio_PrivateKey fails to avoid memory leak.
Fixes: fa6ae88a47 ("Add test for BIO password callback functionality")
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27898)
diff --git a/test/bio_pw_callback_test.c b/test/bio_pw_callback_test.c
index e11368454a..efdb333cff 100644
--- a/test/bio_pw_callback_test.c
+++ b/test/bio_pw_callback_test.c
@@ -372,8 +372,10 @@ int setup_tests(void)
if (!TEST_ptr(bio = BIO_new_file(key_file, "r")))
return 0;
if (!TEST_ptr(PEM_read_bio_PrivateKey(bio, &original_pkey,
- callback_original_pw, NULL)))
+ callback_original_pw, NULL))) {
+ BIO_free(bio);
return 0;
+ }
BIO_free(bio);
/* add all tests */