free entire geminfo list 46/281846/2
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 22 Sep 2022 07:53:04 +0000 (16:53 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 22 Sep 2022 10:20:56 +0000 (19:20 +0900)
The geminfo is list, so it should free all list element. Add
clear_geminfo() function to free all list element and use it.

Change-Id: I3e6cc1ef856bd8a755224ee772b7d064fb9972dc
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
memps.c

diff --git a/memps.c b/memps.c
index 787b899..12f4017 100644 (file)
--- a/memps.c
+++ b/memps.c
@@ -371,6 +371,16 @@ static geminfo *load_gpu_geminfo(void)
        return gilist;
 }
 
+static void clear_geminfo(geminfo *glist)
+{
+       while (glist) {
+               geminfo *gelement = glist;
+               glist = glist->next;
+
+               free(gelement);
+       }
+}
+
 /* b6e82000-b6e83000 rw-p 00020000 b3:19 714        /usr/lib/ld-2.20-2014.11.so  : TM1
  * 7f9389d000-7f9389e000 rw-p 0001f000 b3:12 618                            /usr/lib64/ld-2.20-2014.11.so  : TM2
  * 7fae2e4b2000-7fae2e4b3000 r--p 00021000 fe:01 603                        /usr/lib64/ld-2.20-2014.11.so  : x86-64 Emulator
@@ -1315,10 +1325,8 @@ static int show_map_all_new(int output_type, char *output_path)
        get_mem_info(output_file);
 
        fclose(output_file);
-       if (glist)
-               free(glist);
-       if (gpu_glist)
-               free(gpu_glist);
+       clear_geminfo(glist);
+       clear_geminfo(gpu_glist);
        closedir(pDir);
        return 1;
 }