Fix build warnings 56/96056/2 accepted/tizen_3.0.m2_mobile accepted/tizen_3.0.m2_tv accepted/tizen_3.0.m2_wearable tizen_3.0.m2 tizen_3.0_tv accepted/tizen/3.0.m2/mobile/20170104.141400 accepted/tizen/3.0.m2/tv/20170104.142007 accepted/tizen/3.0.m2/wearable/20170104.142302 accepted/tizen/3.0/common/20161114.082327 accepted/tizen/3.0/ivi/20161110.021610 accepted/tizen/3.0/mobile/20161110.021512 accepted/tizen/3.0/tv/20161110.021532 accepted/tizen/3.0/wearable/20161110.021547 accepted/tizen/common/20161108.131702 accepted/tizen/ivi/20161109.002349 accepted/tizen/mobile/20161109.002255 accepted/tizen/tv/20161109.002314 accepted/tizen/wearable/20161109.002332 submit/tizen/20161108.023400 submit/tizen_3.0.m2/20170104.093751 submit/tizen_3.0/20161109.042255 submit/tizen_3.0_common/20161110.084657
authorHyeongsik Min <hyeongsik.min@samsung.com>
Mon, 7 Nov 2016 12:33:41 +0000 (21:33 +0900)
committerHyeongsik Min <hyeongsik.min@samsung.com>
Tue, 8 Nov 2016 00:40:40 +0000 (09:40 +0900)
Change-Id: Icf8062b8f35b788a9d58ed2a7d207ef80a98bdaa
Signed-off-by: Hyeongsik Min <hyeongsik.min@samsung.com>
memps.c

diff --git a/memps.c b/memps.c
index 84f4f06..deee6d3 100644 (file)
--- a/memps.c
+++ b/memps.c
@@ -78,8 +78,8 @@ struct mapinfo {
        unsigned shared_dirty;
        unsigned private_clean;
        unsigned private_dirty;
-       char perm[4];
-       char name[1];
+       char *perm;
+       char *name;
 };
 
 /* classify normal, graphic and other devices memory */
@@ -333,15 +333,15 @@ mapinfo *read_mapinfo(char** smaps, int line_cnt)
        if (len < 1)
                return 0;
 
-       mi = malloc(sizeof(mapinfo) + len + 16);
+       mi = malloc(sizeof(mapinfo));
        if (mi == 0)
                return 0;
 
-       n = sscanf(line, "%lx-%lx %s %*s %*s %*s %[^\n]",
+       n = sscanf(line, "%lx-%lx %ms %*s %*s %*s %m[^\n]",
                           &mi->start, &mi->end, &mi->perm, &mi->name);
 
-       if (n == 3)
-               strncpy(mi->name, "[anon]", strlen("[anon]")+1);
+       if (n == 3 && !mi->name)
+               mi->name = strndup("[anon]", strlen("[anon]"));
 
        while (line_cnt-- && (line = cgets(smaps))) {
                if (sscanf(line, "Size: %d kB", &mi->size) == 1) {}
@@ -355,10 +355,6 @@ mapinfo *read_mapinfo(char** smaps, int line_cnt)
        }
 
        return mi;
- oops:
-       printf("mi get error\n");
-       free(mi);
-       return 0;
 }
 
 static unsigned total_gem_memory(void)
@@ -674,12 +670,10 @@ mapinfo *load_maps(int pid)
                                milist->private_clean += mi->private_clean;
                                milist->private_dirty += mi->private_dirty;
 
-                               milist->perm[0] = mi->perm[0];
-                               milist->perm[1] = mi->perm[1];
-                               milist->perm[2] = mi->perm[2];
-                               milist->perm[3] = mi->perm[3];
                                milist->end = mi->end;
                                strncpy(milist->perm, mi->perm, 4);
+                               free(mi->perm);
+                               free(mi->name);
                                free(mi);
                                continue;
                        }
@@ -762,6 +756,8 @@ get_trib_mapinfo(unsigned int tgid, mapinfo *milist,
 
                temp = mi;
                mi = mi->next;
+               free(temp->perm);
+               free(temp->name);
                free(temp);
                temp = NULL;
        }