public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix lrealpath memory leak in build_id_to_debug_bfd
@ 2015-06-11 21:41 Keith Seitz
  0 siblings, 0 replies; 3+ messages in thread
From: Keith Seitz @ 2015-06-11 21:41 UTC (permalink / raw)
  To: gdb-patches

Valgrind reports memory leaking from build_id_to_debug_bfd:
==7261== 88 bytes in 2 blocks are definitely lost in loss record 31,319 of 35,132
==7261==    at 0x4A06BCF: malloc (vg_replace_malloc.c:296)
==7261==    by 0x32CA88A9B9: strdup (strdup.c:42)
==7261==    by 0xFE62AB: lrealpath (lrealpath.c:88)
==7261==    by 0x7F7AD6: build_id_to_debug_bfd (build-id.c:116)
==7261==    by 0x7F7BB5: find_separate_debug_file_by_buildid (build-id.c:149)
==7261==    by 0x6D9382: elf_symfile_read (elfread.c:1348)
==7261==    by 0x777F02: read_symbols (symfile.c:875)
==7261==    by 0x778505: syms_from_objfile_1 (symfile.c:1078)
==7261==    by 0x778548: syms_from_objfile (symfile.c:1094)
==7261==    by 0x778746: symbol_file_add_with_addrs (symfile.c:1191)
==7261==    by 0x77893B: symbol_file_add_from_bfd (symfile.c:1280)
==7261==    by 0x8E51E3: solib_read_symbols (solib.c:706)
==7261==    by 0x8E58AF: solib_add (solib.c:1029)

This occurs because commit 1be5090b in bfd, addressing PR 11983, started
taking a copy of the input filename instead of directly caching it.  It
appears that this code was never updated to reflect that API change.

This simple patch creates a cleanup to free the return value for lrealpath.

gdb/ChangeLog

	* build-id.c (build_id_to_debug_bfd): Add cleanup to free
	return value from lrealpath.
---
 gdb/ChangeLog  | 5 +++++
 gdb/build-id.c | 4 ++++
 2 files changed, 9 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9075fcc..9fd417b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2015-06-11  Keith Seitz  <keiths@redhat.com>
+
+	* build-id.c (build_id_to_debug_bfd): Add cleanup to free
+	return value from lrealpath.
+
 2015-06-11  Gary Benson <gbenson@redhat.com>
 
 	* nat/linux-namespaces.c (mnsh_send_message): Use pulongest.
diff --git a/gdb/build-id.c b/gdb/build-id.c
index 8f7bbb4..8f8c2f3 100644
--- a/gdb/build-id.c
+++ b/gdb/build-id.c
@@ -96,6 +96,7 @@ build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
       size_t size = build_id_len;
       char *s;
       char *filename = NULL;
+      struct cleanup *inner;
 
       memcpy (link, debugdir, debugdir_len);
       s = &link[debugdir_len];
@@ -119,7 +120,10 @@ build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
 	continue;
 
       /* We expect to be silent on the non-existing files.  */
+      inner = make_cleanup (xfree, filename);
       abfd = gdb_bfd_open (filename, gnutarget, -1);
+      do_cleanups (inner);
+
       if (abfd == NULL)
 	continue;
 
-- 
2.1.0

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

* Re: [PATCH] Fix lrealpath memory leak in build_id_to_debug_bfd
  2015-06-16 14:57 Doug Evans
@ 2015-06-24 21:16 ` Keith Seitz
  0 siblings, 0 replies; 3+ messages in thread
From: Keith Seitz @ 2015-06-24 21:16 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches

On 06/16/2015 07:57 AM, Doug Evans wrote:
> Keith Seitz writes:
>  > gdb/ChangeLog
>  >
>  >     * build-id.c (build_id_to_debug_bfd): Add cleanup to free
>  >     return value from lrealpath.
> 
> LGTM

I've pushed this. Thank you for taking a look at it.

Keith

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

* Re: [PATCH] Fix lrealpath memory leak in build_id_to_debug_bfd
@ 2015-06-16 14:57 Doug Evans
  2015-06-24 21:16 ` Keith Seitz
  0 siblings, 1 reply; 3+ messages in thread
From: Doug Evans @ 2015-06-16 14:57 UTC (permalink / raw)
  To: Keith Seitz; +Cc: gdb-patches

Keith Seitz writes:
  > gdb/ChangeLog
  >
  > 	* build-id.c (build_id_to_debug_bfd): Add cleanup to free
  > 	return value from lrealpath.

LGTM

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

end of thread, other threads:[~2015-06-24 21:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-11 21:41 [PATCH] Fix lrealpath memory leak in build_id_to_debug_bfd Keith Seitz
2015-06-16 14:57 Doug Evans
2015-06-24 21:16 ` Keith Seitz

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