Protect against some memory leaks
[platform/upstream/libunwind.git] / src / dwarf / Gfind_proc_info-lsb.c
index bd2c058..fdc5ef6 100644 (file)
@@ -139,6 +139,8 @@ load_debug_frame (const char *file, char **buf, size_t *bufsize, int is_local)
       if (strcmp (secname, ".debug_frame") == 0)
         {
           *bufsize = sec_hdrs[i].sh_size;
+          if (*buf)
+            free(*buf);
           *buf = malloc (*bufsize);
 
           fseek (f, sec_hdrs[i].sh_offset, SEEK_SET);
@@ -151,6 +153,8 @@ load_debug_frame (const char *file, char **buf, size_t *bufsize, int is_local)
       else if (strcmp (secname, ".gnu_debuglink") == 0)
         {
           linksize = sec_hdrs[i].sh_size;
+          if (linkbuf)
+            free(linkbuf);
           linkbuf = malloc (linksize);
 
           fseek (f, sec_hdrs[i].sh_offset, SEEK_SET);