Fix lrealpath memory leak in build_id_to_debug_bfd
authorKeith Seitz <keiths@redhat.com>
Thu, 4 Jun 2015 17:13:50 +0000 (10:13 -0700)
committerKeith Seitz <keiths@redhat.com>
Wed, 24 Jun 2015 21:09:19 +0000 (14:09 -0700)
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
gdb/build-id.c

index 19144edf3485aa3e7f071df3b0c18e408d5ed262..a52624b4538099fa14fbaeacd2f99a97fbb1e130 100644 (file)
@@ -1,3 +1,8 @@
+2015-06-24  Keith Seitz  <keiths@redhat.com>
+
+       * build-id.c (build_id_to_debug_bfd): Add cleanup to free
+       return value from lrealpath.
+
 2015-06-24  Mike Frysinger  <vapier@gentoo.org>
 
        * remote-sim.c (gdbsim_open): Move sysroot update to the top.
index ebf9f4534807650f9bcf6a169e18539b75a70eb9..c89cd55c262ab9bbc10f282b36b811a08f0fb9d3 100644 (file)
@@ -93,6 +93,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];
@@ -116,7 +117,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;
 
This page took 0.028248 seconds and 4 git commands to generate.