Change-Id: I7ef2563bee2bf1690b2a38554cc15bf0e10f92fc
return;
map->list_index = malloc(sizeof(struct mem_region*) * map->num_regions);
+
+ if (map->list_index == NULL)
+ return;
+
cur = map->list_head;
for (i = 0; cur != NULL; cur = cur->next) {
map->list_index[i++] = cur;
{
char buf[32];
struct dirent **namelist;
- int cur, i, n;
+ int cur, i, n, res;
snprintf(buf, sizeof(buf), "/proc/%d/task", pid);
n = scandir(buf, &namelist, dir_select, NULL);
+ res = n;
if (n < 0) {
perror(buf);
return -1;
} else {
*tids = malloc(sizeof(int)*n);
+ if (*tids == NULL) {
+ res = -1;
+ goto exit;
+ }
+
i = 0;
while (i < n) {
cur = atoi(namelist[i]->d_name);
(*tids)[i] = cur;
- free(namelist[i++]);
}
- free(namelist);
}
- return n;
+exit:
+ for (i = 0; i < n; i++)
+ free(namelist[i]);
+ free(namelist);
+
+ return res;
}
char *get_thread_states(const int *tids, int n)