Fix SVACE warnings 37/249937/1
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 17 Dec 2020 11:12:27 +0000 (12:12 +0100)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 17 Dec 2020 11:54:31 +0000 (12:54 +0100)
Change-Id: I7ef2563bee2bf1690b2a38554cc15bf0e10f92fc

src/crash-stack/mem_map.c
src/crash-stack/proc.c

index e3c48f5..66e721c 100644 (file)
@@ -624,6 +624,10 @@ void mem_map_create_region_index(struct mem_map *map)
         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;
index 8946c21..0a2c969 100644 (file)
@@ -268,26 +268,35 @@ int get_threads(int pid, int **tids)
 {
     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)