public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PR26069, strip/objcopy memory leaks
@ 2020-06-03  8:40 Alan Modra
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2020-06-03  8:40 UTC (permalink / raw)
  To: binutils

	PR 26069
	* objcopy.c (copy_relocations_in_section): Free relpp on error.
	Don't accidentally free isection->orelocation.

diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 5760d06a85..3866c7f458 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -4294,6 +4294,7 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
 	      status = 1;
 	      bfd_nonfatal_message (NULL, ibfd, isection,
 				    _("relocation count is negative"));
+	      free (relpp);
 	      return;
 	    }
 	}
@@ -4318,7 +4319,7 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
 		  temp_relpp [temp_relcount++] = relpp [i];
 	    }
 	  relcount = temp_relcount;
-	  if (isection->orelocation == NULL)
+	  if (relpp != isection->orelocation)
 	    free (relpp);
 	  relpp = temp_relpp;
 	}
@@ -4327,7 +4328,8 @@ copy_relocations_in_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
       if (relcount == 0)
 	{
 	  osection->flags &= ~SEC_RELOC;
-	  free (relpp);
+	  if (relpp != isection->orelocation)
+	    free (relpp);
 	}
     }
 }

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 2+ messages in thread

* PR26069, strip/objcopy memory leaks
@ 2020-06-03  8:39 Alan Modra
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2020-06-03  8:39 UTC (permalink / raw)
  To: binutils

	PR 26029
	* elf.c (_bfd_elf_close_and_cleanup): Free elf_shstrtab for
	core files as well as objects.

diff --git a/bfd/elf.c b/bfd/elf.c
index e335ff7efb..9ca42e10d8 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -9438,7 +9438,9 @@ bfd_boolean
 _bfd_elf_close_and_cleanup (bfd *abfd)
 {
   struct elf_obj_tdata *tdata = elf_tdata (abfd);
-  if (bfd_get_format (abfd) == bfd_object && tdata != NULL)
+  if (tdata != NULL
+      && (bfd_get_format (abfd) == bfd_object
+	  || bfd_get_format (abfd) == bfd_core))
     {
       if (elf_tdata (abfd)->o != NULL && elf_shstrtab (abfd) != NULL)
 	_bfd_elf_strtab_free (elf_shstrtab (abfd));

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-03  8:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-03  8:40 PR26069, strip/objcopy memory leaks Alan Modra
  -- strict thread matches above, loose matches on Subject: below --
2020-06-03  8:39 Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).