]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR26069, strip/objcopy memory leaks
authorAlan Modra <amodra@gmail.com>
Wed, 3 Jun 2020 07:25:39 +0000 (16:55 +0930)
committerAlan Modra <amodra@gmail.com>
Wed, 3 Jun 2020 08:29:44 +0000 (17:59 +0930)
PR 26069
* objcopy.c (copy_relocations_in_section): Free relpp on error.
Don't accidentally free isection->orelocation.

binutils/ChangeLog
binutils/objcopy.c

index 7eb900935fa7df981a84315baacfa5d383c4bc0d..ff1e52c14dde8f1a8d6180ea83838fc0860efd6d 100644 (file)
@@ -1,3 +1,9 @@
+2020-06-03  Alan Modra  <amodra@gmail.com>
+
+       PR 26069
+       * objcopy.c (copy_relocations_in_section): Free relpp on error.
+       Don't accidentally free isection->orelocation.
+
 2020-06-02  Alan Modra  <amodra@gmail.com>
 
        * testsuite/binutils-all/ar.exp (obj): Set up object file name
index 5760d06a85959ce53ea7e52b46504cd721bfc1f5..3866c7f458861dd522a44e07b20d8485f66719b1 100644 (file)
@@ -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);
        }
     }
 }