Adjust scope of map info list variable 47/281847/2 accepted/tizen_7.0_unified accepted/tizen_7.0_unified_hotfix tizen_7.0 tizen_7.0_hotfix accepted/tizen/7.0/unified/20221110.061330 accepted/tizen/7.0/unified/hotfix/20221116.105745 accepted/tizen/unified/20220923.125202 tizen_7.0_m2_release
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 22 Sep 2022 07:57:11 +0000 (16:57 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 22 Sep 2022 10:20:56 +0000 (19:20 +0900)
The milist, map info list is allocated for each process and freed
by get_trib_mapinfo(), but the pointer life cycle is not well
shown. Adjust variable scope for each process, and add comment
about its free in get_trib_mapinfo().

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

diff --git a/memps.c b/memps.c
index 12f4017..b56ff3a 100644 (file)
--- a/memps.c
+++ b/memps.c
@@ -1117,7 +1117,6 @@ static int show_map_all_new(int output_type, char *output_path)
        DIR *pDir = NULL;
        struct dirent *curdir;
        unsigned int pid;
-       mapinfo *milist;
        geminfo *glist;
        geminfo *gpu_glist;
        unsigned total_pss = 0;
@@ -1184,6 +1183,8 @@ static int show_map_all_new(int output_type, char *output_path)
 
        errno = 0;
        while ((curdir = readdir(pDir)) != NULL && !errno) {
+               mapinfo *milist;
+
                pid = atoi(curdir->d_name);
                if (pid < 1 || pid > pid_max || pid == getpid())
                        continue;
@@ -1195,7 +1196,7 @@ static int show_map_all_new(int output_type, char *output_path)
                if (milist == 0)
                        continue;
 
-               /* get classified map info */
+               /* get classified map info, milist will be freed */
                get_trib_mapinfo(pid, milist, glist, gpu_glist, &tmi);
                oom_score_adj = get_oomscoreadj(pid, oom_path);