public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* Synthetic symbol leak in in elf_x86_64_get_synthetic_symtab and elf_read_minimal_symbols
@ 2017-08-07 15:19 Alex Lindsay
  2017-08-11  9:27 ` Yao Qi
  0 siblings, 1 reply; 11+ messages in thread
From: Alex Lindsay @ 2017-08-07 15:19 UTC (permalink / raw)
  To: gdb-patches

Detected this leak with valgrind memcheck:

==21225== 463 (336 direct, 127 indirect) bytes in 1 blocks are 
definitely lost in loss record 10,770 of 10,949^M
==21225==    at 0x4C2DB8F: malloc (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)^M
==21225==    by 0x6C6DA2: bfd_malloc (libbfd.c:193)^M
==21225==    by 0x6C6F4D: bfd_zmalloc (libbfd.c:278)^M
==21225==    by 0x6D252E: elf_x86_64_get_synthetic_symtab 
(elf64-x86-64.c:6846)^M
==21225==    by 0x4B397A: elf_read_minimal_symbols (elfread.c:1124)^M
==21225==    by 0x4B397A: elf_symfile_read(objfile*, 
enum_flags<symfile_add_flag>) (elfread.c:1182)^M
==21225==    by 0x63AC94: read_symbols(objfile*, 
enum_flags<symfile_add_flag>) (symfile.c:861)^M
==21225==    by 0x63A773: syms_from_objfile_1 (symfile.c:1062)

We perform a couple of  dynamic allocations in 
elf_x86_64_get_synthetic_symtab (elf64-x86-64.c):

   s = *ret = (asymbol *) bfd_zmalloc (size);

   names = (char *) bfd_malloc (size);

that appear to never get freed. My patch for this:

diff --git a/gdb/elfread.c b/gdb/elfread.c
index ece704ca7c..5ed8a6f957 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1144,6 +1144,9 @@ elf_read_minimal_symbols (struct objfile *objfile, 
int symfile_flags,

    if (symtab_create_debug)
      fprintf_unfiltered (gdb_stdlog, "Done reading minimal symbols.\n");
+  if (synthcount > 0)
+    xfree ((char *) synthsyms->name);
+  xfree (synthsyms);
  }

  /* Scan and build partial symbols for a symbol file.

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

end of thread, other threads:[~2017-08-17 22:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-07 15:19 Synthetic symbol leak in in elf_x86_64_get_synthetic_symtab and elf_read_minimal_symbols Alex Lindsay
2017-08-11  9:27 ` Yao Qi
2017-08-11 15:07   ` Alex Lindsay
2017-08-11 15:31   ` H.J. Lu
2017-08-11 15:46     ` Yao Qi
2017-08-11 16:44       ` H.J. Lu
2017-08-11 21:20         ` Alex Lindsay
2017-08-17 11:00           ` Yao Qi
2017-08-17 12:31             ` Philippe Waroquiers
2017-08-17 17:42               ` Pedro Alves
2017-08-17 22:32                 ` [PATCH] Plug line_header leaks (Re: Synthetic symbol leak in in elf_x86_64_get_synthetic_symtab and elf_read_minimal_symbols) Pedro Alves

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).