public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] elf32_arm_get_synthetic_symtab memory leak
@ 2023-06-21  6:20 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-06-21  6:20 UTC (permalink / raw)
  To: bfd-cvs

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

commit 08edd976116312550831cdfd3b5a4b069bdcca80
Author: Alan Modra <amodra@gmail.com>
Date:   Wed Jun 21 14:33:59 2023 +0930

    elf32_arm_get_synthetic_symtab memory leak
    
    ARM get_synthetic_symtab reads .plt and caches that data.  Caching the
    data doesn't make a lot of sense since get_synthetic_symtab is only
    called once per bfd, and the memory might be put to better use.  It
    also leaks on closing the bfd.
    
            * elf32-arm.c (elf32_arm_get_synthetic_symtab): Don't cache
            plt contents.  Free plt data before returning.

Diff:
---
 bfd/elf32-arm.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 2afe67abdf1..3b7cee3de1c 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -20073,15 +20073,9 @@ elf32_arm_get_synthetic_symtab (bfd *abfd,
   if (!elf32_arm_size_info.slurp_reloc_table (abfd, relplt, dynsyms, true))
     return -1;
 
-  data = plt->contents;
-  if (data == NULL)
-    {
-      if (!bfd_get_full_section_contents (abfd, plt, &data)
-	  || data == NULL)
-	return -1;
-      plt->contents = data;
-      plt->flags |= SEC_IN_MEMORY;
-    }
+  data = NULL;
+  if (!bfd_get_full_section_contents (abfd, plt, &data))
+    return -1;
 
   count = NUM_SHDR_ENTRIES (hdr);
   size = count * sizeof (asymbol);
@@ -20093,13 +20087,13 @@ elf32_arm_get_synthetic_symtab (bfd *abfd,
 	size += sizeof ("+0x") - 1 + 8;
     }
 
-  s = *ret = (asymbol *) bfd_malloc (size);
-  if (s == NULL)
-    return -1;
-
   offset = elf32_arm_plt0_size (abfd, data);
-  if (offset == (bfd_vma) -1)
-    return -1;
+  if (offset == (bfd_vma) -1
+      || (s = *ret = (asymbol *) bfd_malloc (size)) == NULL)
+    {
+      free (data);
+      return -1;
+    }
 
   names = (char *) (s + count);
   p = relplt->relocation;
@@ -20144,6 +20138,7 @@ elf32_arm_get_synthetic_symtab (bfd *abfd,
       offset += plt_size;
     }
 
+  free (data);
   return n;
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-21  6:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-21  6:20 [binutils-gdb] elf32_arm_get_synthetic_symtab memory leak 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).