From: Alan Modra Date: Wed, 3 Jun 2020 07:25:39 +0000 (+0930) Subject: PR26069, strip/objcopy memory leaks X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4a32244804f942a54960039c7968b1df2a177b4d;p=binutils-gdb.git PR26069, strip/objcopy memory leaks PR 26069 * objcopy.c (copy_relocations_in_section): Free relpp on error. Don't accidentally free isection->orelocation. --- diff --git a/binutils/ChangeLog b/binutils/ChangeLog index 7eb900935fa..ff1e52c14dd 100644 --- a/binutils/ChangeLog +++ b/binutils/ChangeLog @@ -1,3 +1,9 @@ +2020-06-03 Alan Modra + + PR 26069 + * objcopy.c (copy_relocations_in_section): Free relpp on error. + Don't accidentally free isection->orelocation. + 2020-06-02 Alan Modra * testsuite/binutils-all/ar.exp (obj): Set up object file name diff --git a/binutils/objcopy.c b/binutils/objcopy.c index 5760d06a859..3866c7f4588 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); } } }