]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
test/timing_load_creds.c: Free contents in error handling to avoid memory leak
authorJiashengJiang <jiasheng@purdue.edu>
Mon, 5 May 2025 18:52:40 +0000 (14:52 -0400)
committerPauli <ppzgs1@gmail.com>
Thu, 8 May 2025 23:32:22 +0000 (09:32 +1000)
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 <jiasheng@purdue.edu>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <ppzgs1@gmail.com>
(Merged from https://github.com/openssl/openssl/pull/27570)

test/timing_load_creds.c

index 978523c2cd6a4b117a5b358b54633f9cd24c325c..c5a8d6497b6711ddf2f706ba85003b448a530241 100644 (file)
@@ -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);
     }