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 */
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) {}
}
return mi;
- oops:
- printf("mi get error\n");
- free(mi);
- return 0;
}
static unsigned total_gem_memory(void)
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;
}
temp = mi;
mi = mi->next;
+ free(temp->perm);
+ free(temp->name);
free(temp);
temp = NULL;
}