From: JiashengJiang Date: Mon, 5 May 2025 18:52:40 +0000 (-0400) Subject: test/timing_load_creds.c: Free contents in error handling to avoid memory leak X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f4d9904763e59db031007f4a938f1f8b96fdcee7;p=thirdparty%2Fopenssl.git test/timing_load_creds.c: Free contents in error handling to avoid memory leak Add a call to OPENSSL_free() in the error handling path to ensure contents is properly freed and prevent a memory leak. Fixes: 45479dcee1 ("test/timing_load_creds.c: fix coding style and other (mostly minor) issues") Signed-off-by: JiashengJiang Reviewed-by: Tomas Mraz Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/27570) --- diff --git a/test/timing_load_creds.c b/test/timing_load_creds.c index 978523c2cd6..c5a8d6497b6 100644 --- a/test/timing_load_creds.c +++ b/test/timing_load_creds.c @@ -150,6 +150,7 @@ int main(int ac, char **av) } fp = fopen(av[0], "r"); if ((long)fread(contents, 1, sb.st_size, fp) != sb.st_size) { + OPENSSL_free(contents); perror("fread"); exit(EXIT_FAILURE); } @@ -171,10 +172,12 @@ int main(int ac, char **av) } if (gettimeofday(&e_start, NULL) < 0) { + OPENSSL_free(contents); perror("elapsed start"); exit(EXIT_FAILURE); } if (getrusage(RUSAGE_SELF, &start) < 0) { + OPENSSL_free(contents); perror("start"); exit(EXIT_FAILURE); } @@ -189,10 +192,12 @@ int main(int ac, char **av) } } if (getrusage(RUSAGE_SELF, &end) < 0) { + OPENSSL_free(contents); perror("getrusage"); exit(EXIT_FAILURE); } if (gettimeofday(&e_end, NULL) < 0) { + OPENSSL_free(contents); perror("gettimeofday"); exit(EXIT_FAILURE); }