Fix potential memory leaks in some of the binutils source files.
[deliverable/binutils-gdb.git] / binutils / rddbg.c
index 4a690f628220952a8b5168ff25e6d702c01b24eb..2a238737bb7748f9faf3f69f67ab0879c756036e 100644 (file)
@@ -128,6 +128,8 @@ read_section_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount,
              fprintf (stderr, "%s: %s: %s\n",
                       bfd_get_filename (abfd), names[i].secname,
                       bfd_errmsg (bfd_get_error ()));
+             free (shandle);
+             free (stabs);
              return FALSE;
            }
 
@@ -138,6 +140,9 @@ read_section_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount,
              fprintf (stderr, "%s: %s: %s\n",
                       bfd_get_filename (abfd), names[i].strsecname,
                       bfd_errmsg (bfd_get_error ()));
+             free (shandle);
+             free (strings);
+             free (stabs);
              return FALSE;
            }
          /* Zero terminate the strings table, just in case.  */
@@ -146,7 +151,11 @@ read_section_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount,
            {
              shandle = start_stab (dhandle, abfd, TRUE, syms, symcount);
              if (shandle == NULL)
-               return FALSE;
+               {
+                 free (strings);
+                 free (stabs);
+                 return FALSE;
+               }
            }
 
          *pfound = TRUE;
@@ -213,17 +222,16 @@ read_section_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount,
                                   (long) (stab - stabs) / 12);
                          break;
                        }
-                     else
-                       s = concat (s, (char *) strings + strx,
-                                   (const char *) NULL);
+
+                     s = concat (s, (char *) strings + strx,
+                                 (const char *) NULL);
 
                      /* We have to restore the backslash, because, if
                         the linker is hashing stabs strings, we may
                         see the same string more than once.  */
                      *p = '\\';
 
-                     if (f != NULL)
-                       free (f);
+                     free (f);
                      f = s;
                    }
 
@@ -233,6 +241,10 @@ read_section_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount,
                    {
                      stab_context ();
                      free_saved_stabs ();
+                     free (f);
+                     free (shandle);
+                     free (stabs);
+                     free (strings);
                      return FALSE;
                    }
 
This page took 0.024406 seconds and 4 git commands to generate.