From: Tomas Mraz Date: Tue, 29 Apr 2025 09:56:23 +0000 (+0200) Subject: apps/prime.c: Fix memory leak of a BIGNUM X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=573db120795ced4750c8de2a7dccb1346dded6ff;p=thirdparty%2Fopenssl.git apps/prime.c: Fix memory leak of a BIGNUM Reviewed-by: Richard Levitte Reviewed-by: Matt Caswell Reviewed-by: Viktor Dukhovni (Merged from https://github.com/openssl/openssl/pull/27521) --- diff --git a/apps/prime.c b/apps/prime.c index c582de98a5b..a8c7aaec445 100644 --- a/apps/prime.c +++ b/apps/prime.c @@ -40,9 +40,10 @@ static int check_num(const char *s, const int is_hex) return s[i] == 0; } -static void process_num(const char *s, const int is_hex, BIGNUM *bn) +static void process_num(const char *s, const int is_hex) { int r; + BIGNUM *bn = NULL; r = check_num(s, is_hex); @@ -51,11 +52,13 @@ static void process_num(const char *s, const int is_hex, BIGNUM *bn) if (!r) { BIO_printf(bio_err, "Failed to process value (%s)\n", s); + BN_free(bn); return; } BN_print(bio_out, bn); r = BN_check_prime(bn, NULL, NULL); + BN_free(bn); if (r < 0) { BIO_printf(bio_err, "Error checking prime\n"); return; @@ -173,7 +176,7 @@ opthelp: int valid_digits_length = 0; if (!in_file) { - process_num(argv[0], hex, bn); + process_num(argv[0], hex); } else { in = bio_open_default_quiet(argv[0], 'r', 0); if (in == NULL) { @@ -193,7 +196,7 @@ opthelp: valid_digits_length = strspn(file_read_buf, "1234567890abcdefABCDEF"); file_read_buf[valid_digits_length] = '\0'; - process_num(file_read_buf, hex, bn); + process_num(file_read_buf, hex); } if (bytes_read < 0)