This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Fix ridiculously small memory leak.


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

commit cf0ad5bbf2d3fdb751b5f3f49e55d251d48c7416
Author: Nick Clifton <nickc@redhat.com>
Date:   Fri Jan 4 12:11:51 2019 +0000

    Fix ridiculously small memory leak.
    
    	PR 24001
    	* objcopy.c (copy_object): Free dhandle after writing out the
    	debug information.
    	* objdump.c (dump_bfd): Free dhandle after printing out the debug
    	information.

Diff:
---
 binutils/ChangeLog | 8 ++++++++
 binutils/objcopy.c | 9 ++++++++-
 binutils/objdump.c | 2 ++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 3fc4606..c1b2d0b 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,11 @@
+2019-01-04  Nick Clifton  <nickc@redhat.com>
+
+	PR 24001
+	* objcopy.c (copy_object): Free dhandle after writing out the
+	debug information.
+	* objdump.c (dump_bfd): Free dhandle after printing out the debug
+	information.
+
 2019-01-01  Alan Modra  <amodra@gmail.com>
 
 	Update year range in copyright notice of all files.
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 9bc1230..0e17b86 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -3087,7 +3087,14 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
 
   if (convert_debugging && dhandle != NULL)
     {
-      if (! write_debugging_info (obfd, dhandle, &symcount, &osympp))
+      bfd_boolean res;
+
+      res = write_debugging_info (obfd, dhandle, &symcount, &osympp);
+
+      free (dhandle);
+      dhandle = NULL; /* Paranoia...  */
+
+      if (! res)
 	{
 	  status = 1;
 	  return FALSE;
diff --git a/binutils/objdump.c b/binutils/objdump.c
index 37a28d5..220d93a 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -3692,6 +3692,8 @@ dump_bfd (bfd *abfd)
 			 bfd_get_filename (abfd));
 	      exit_status = 1;
 	    }
+
+	  free (dhandle);
 	}
       /* PR 6483: If there was no STABS debug info in the file, try
 	 DWARF instead.  */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]