PR23952, memory leak in _bfd_generic_read_minisymbols
authorAlan Modra <amodra@gmail.com>
Fri, 7 Dec 2018 13:09:42 +0000 (23:39 +1030)
committerAlan Modra <amodra@gmail.com>
Fri, 7 Dec 2018 13:41:16 +0000 (00:11 +1030)
bfd/
PR 23952
* syms.c (_bfd_generic_read_minisymbols): Free syms before
returning with zero symcount.
binutils/
* nm.c (display_rel_file): Use xrealloc to increase minisyms
for synthetic symbols.

bfd/ChangeLog
bfd/syms.c
binutils/ChangeLog
binutils/nm.c

index 8a3727104ce9b0fd04349296a98abcef5bee1091..b7d671765f3c9bc9c16d4da662bc7c1e5f374238 100644 (file)
@@ -1,3 +1,9 @@
+2018-12-07  Alan Modra  <amodra@gmail.com>
+
+       PR 23952
+       * syms.c (_bfd_generic_read_minisymbols): Free syms before
+       returning with zero symcount.
+
 2018-12-06  Alan Modra  <amodra@gmail.com>
 
        * elf32-ppc.c (ppc_elf_howto_raw <R_PPC_VLE_ADDR20>): Correct
index e09640ab74a5416c1ad44da08091e54d786b932c..cbf85cb16d74f8fdc1ec322b1e3bb437d544a1a4 100644 (file)
@@ -822,9 +822,16 @@ _bfd_generic_read_minisymbols (bfd *abfd,
   if (symcount < 0)
     goto error_return;
 
-  *minisymsp = syms;
-  *sizep = sizeof (asymbol *);
-
+  if (symcount == 0)
+    /* We return 0 above when storage is 0.  Exit in the same state
+       here, so as to not complicate callers with having to deal with
+       freeing memory for zero symcount.  */
+    free (syms);
+  else
+    {
+      *minisymsp = syms;
+      *sizep = sizeof (asymbol *);
+    }
   return symcount;
 
  error_return:
index d865bf6d327b9b9c1f7106b1b95dbdf10ab26db2..a75f83b923b0aa847066c5fb20a36781d48d6d4b 100644 (file)
@@ -1,3 +1,8 @@
+2018-12-07  Alan Modra  <amodra@gmail.com>
+
+       * nm.c (display_rel_file): Use xrealloc to increase minisyms
+       for synthetic symbols.
+
 2018-12-07  Nick Clifton  <nickc@redhat.com>
 
        * addr2line.c (demangle_flags): New static variable.
index 8807832f978a47389b3a63a9f830380de76f9451..39083c3f4e83dc36630163b592185cae57a33fb7 100644 (file)
@@ -1175,17 +1175,14 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
       if (synth_count > 0)
        {
          asymbol **symp;
-         void *new_mini;
          long i;
 
-         new_mini = xmalloc ((symcount + synth_count + 1) * sizeof (*symp));
-         symp = (asymbol **) new_mini;
-         memcpy (symp, minisyms, symcount * sizeof (*symp));
-         symp += symcount;
+         minisyms = xrealloc (minisyms,
+                              (symcount + synth_count + 1) * sizeof (*symp));
+         symp = (asymbol **) minisyms + symcount;
          for (i = 0; i < synth_count; i++)
            *symp++ = synthsyms + i;
          *symp = 0;
-         minisyms = new_mini;
          symcount += synth_count;
        }
     }
This page took 0.028268 seconds and 4 git commands to generate.