Fix alloc failure handling 51/234651/1
authorMichal Bloch <m.bloch@samsung.com>
Wed, 27 May 2020 21:23:14 +0000 (23:23 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Wed, 27 May 2020 21:23:22 +0000 (23:23 +0200)
Thanks SVACE

Change-Id: Ic2774946c10e7d9e5e9c6279446aa388d0cbb84d
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
src/coredump/_UCD_create.c
src/dwarf/Gfind_proc_info-lsb.c

index f22664b..19a5371 100644 (file)
@@ -238,6 +238,11 @@ _UCD_create(const char *filename)
 
             ui->n_threads = n_threads;
             ui->threads = malloc(sizeof (void *) * n_threads);
+            if (!ui->threads)
+              {
+                Debug(0, "Allocation failed");
+                goto err;
+              }
 
             n_threads = 0;
             note_hdr = (Elf32_Nhdr *)ui->note_phdr;
index 6e1f4c3..bd2c058 100644 (file)
@@ -169,10 +169,7 @@ load_debug_frame (const char *file, char **buf, size_t *bufsize, int is_local)
 
   /* Ignore separate debug files which contain a .gnu_debuglink section. */
   if (linkbuf && is_local == -1)
-    {
-      free (linkbuf);
-      return 1;
-    }
+    goto alloc_error;
 
   if (*buf == NULL && linkbuf != NULL && memchr (linkbuf, 0, linksize) != NULL)
     {
@@ -182,8 +179,16 @@ load_debug_frame (const char *file, char **buf, size_t *bufsize, int is_local)
 
       /* XXX: Don't bother with the checksum; just search for the file.  */
       basedir = malloc (strlen (file) + 1);
+      if (!basedir)
+        goto alloc_error;
+
       newname = malloc (strlen (linkbuf) + strlen (debugdir)
                         + strlen (file) + 9);
+      if (!newname)
+        {
+          free(basedir);
+          goto alloc_error;
+        }
 
       p = strrchr (file, '/');
       if (p != NULL)
@@ -227,9 +232,11 @@ load_debug_frame (const char *file, char **buf, size_t *bufsize, int is_local)
 file_error:
   free(stringtab);
   free(sec_hdrs);
-  free(linkbuf);
   fclose(f);
 
+alloc_error:
+  free(linkbuf);
+
   return 1;
 }