fixed memory leak of not freed jobs_eta in several cases
authorDenis Pronin <dannftk@yandex.ru>
Sun, 10 Apr 2022 12:21:06 +0000 (15:21 +0300)
committerDenis Pronin <dannftk@yandex.ru>
Sun, 17 Apr 2022 14:13:36 +0000 (17:13 +0300)
used 'free' function in 'print_thread_status' and in
'show_thread_status_json' functions to free jobs_eta previously
allocated

Signed-off-by: Denis Pronin <dannftk@yandex.ru>
eta.c
stat.c

diff --git a/eta.c b/eta.c
index 17970c78dbfd94261403b6c67c536e875ad65fdb..6017ca3102eb3b5795915a676e1140728b72579c 100644 (file)
--- a/eta.c
+++ b/eta.c
@@ -3,6 +3,7 @@
  */
 #include <unistd.h>
 #include <string.h>
+#include <stdlib.h>
 #ifdef CONFIG_VALGRIND_DEV
 #include <valgrind/drd.h>
 #else
@@ -707,10 +708,10 @@ void print_thread_status(void)
        size_t size;
 
        je = get_jobs_eta(false, &size);
-       if (je)
+       if (je) {
                display_thread_status(je);
-
-       free(je);
+               free(je);
+       }
 }
 
 void print_status_init(int thr_number)
diff --git a/stat.c b/stat.c
index 356083e25ff5e36359cafd8e7fedc158634e2d68..949af5edd49ffa05dfa16bbef70c7d1037de8261 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <math.h>
@@ -1698,6 +1699,7 @@ static struct json_object *show_thread_status_json(struct thread_stat *ts,
        if (je) {
                json_object_add_value_int(root, "eta", je->eta_sec);
                json_object_add_value_int(root, "elapsed", je->elapsed_sec);
+               free(je);
        }
 
        if (opt_list)