[binutils-gdb] memory leak in objdump disassemble_section

Alan Modra amodra@sourceware.org
Wed Feb 7 12:15:14 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3ef23ee92631014b6e72e63aa0d6ecc467392546

commit 3ef23ee92631014b6e72e63aa0d6ecc467392546
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Feb 7 11:58:10 2024 +1030

    memory leak in objdump disassemble_section
    
            * objdump.c (disassemble_section): Free rel_ppstart on error path.

Diff:
---
 binutils/objdump.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/binutils/objdump.c b/binutils/objdump.c
index 49e944b1dfd..7beb221cb2f 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -3795,6 +3795,7 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
     {
       non_fatal (_("Reading section %s failed because: %s"),
 		 section->name, bfd_errmsg (bfd_get_error ()));
+      free (rel_ppstart);
       return;
     }
 
@@ -4075,9 +4076,7 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
     }
 
   free (data);
-
-  if (rel_ppstart != NULL)
-    free (rel_ppstart);
+  free (rel_ppstart);
 }
 
 /* Disassemble the contents of an object file.  */


More information about the Binutils-cvs mailing list