Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Yao Qi <qiyaoltc@gmail.com>
To: Alex Lindsay <alexlindsay239@gmail.com>
Cc: "H.J. Lu" <hjl.tools@gmail.com>,  GDB <gdb-patches@sourceware.org>
Subject: Re: Synthetic symbol leak in in elf_x86_64_get_synthetic_symtab and elf_read_minimal_symbols
Date: Thu, 17 Aug 2017 11:00:00 -0000	[thread overview]
Message-ID: <86d17umpcg.fsf@gmail.com> (raw)
In-Reply-To: <b70efed4-07e7-e9dc-d466-1d9323319b10@gmail.com> (Alex Lindsay's	message of "Fri, 11 Aug 2017 16:20:32 -0500")

Alex Lindsay <alexlindsay239@gmail.com> writes:

> I can verify that the objdump example is fixed in HEAD, but I still
> get this leak with `valgrind --leak-check=full
> --show-leak-kinds=definite gdb ./hello`:

Yes, because your patch is not pushed in yet :)  I tweaked your patch a
little bit, and pushed it in.  Again, thanks for your contribution.  Do
you still see other memory leak issues after this fix?

-- 
Yao (齐尧)

From ba7139188c75a9c620cadea59158c5ffcab28acf Mon Sep 17 00:00:00 2001
From: Alex Lindsay <alexlindsay239@gmail.com>
Date: Thu, 17 Aug 2017 11:53:53 +0100
Subject: [PATCH] Synthetic symbol leak in elf_read_minimal_symbols

Detected this leak with valgrind memcheck:

==30840== 194 bytes in 1 blocks are definitely lost in loss record 9,138 of 10,922
==30840==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==30840==    by 0x80DF82: bfd_malloc (libbfd.c:193)
==30840==    by 0x80E12D: bfd_zmalloc (libbfd.c:278)
==30840==    by 0x819E80: elf_x86_64_get_synthetic_symtab (elf64-x86-64.c:6835)
==30840==    by 0x4F7B01: elf_read_minimal_symbols(objfile*, int, elfinfo const*) (elfread.c:1124)
==30840==    by 0x4F7CE7: elf_symfile_read(objfile*, enum_flags<symfile_add_flag>) (elfread.c:1182)
==30840==    by 0x7557FC: read_symbols(objfile*, enum_flags<symfile_add_flag>) (symfile.c:861)
==30840==    by 0x755EE1: syms_from_objfile_1(objfile*, section_addr_info*, enum_flags<symfile_add_flag>) (symfile.c:1062)

We perform a dynamic allocation in
elf64-x86-64.c:elf_x86_64_get_synthetic_symtab

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

that appear to never get freed.

gdb:

2017-08-17  Alex Lindsay  <alexlindsay239@gmail.com>

	* elfread.c (elf_read_minimal_symbols): xfree synthsyms.

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 10d63b0..d2c194e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2017-08-17  Alex Lindsay  <alexlindsay239@gmail.com>  (tiny change)
+
+	* elfread.c (elf_read_minimal_symbols): xfree synthsyms.
+
 2017-08-17  Ruslan Kabatsayev  <b7.10110111@gmail.com>
 
 	* NEWS: Mention new shortcuts for nexti and stepi in TUI
diff --git a/gdb/elfread.c b/gdb/elfread.c
index ece704c..a654661 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -1132,6 +1132,9 @@ elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
 	synth_symbol_table[i] = synthsyms + i;
       elf_symtab_read (reader, objfile, ST_SYNTHETIC, synthcount,
 		       synth_symbol_table.get (), true);
+
+      xfree (synthsyms);
+      synthsyms = NULL;
     }
 
   /* Install any minimal symbols that have been collected as the current


  reply	other threads:[~2017-08-17 11:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-07 15:19 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86d17umpcg.fsf@gmail.com \
    --to=qiyaoltc@gmail.com \
    --cc=alexlindsay239@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=hjl.tools@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox