Patchwork Free synthsyms and member names in function elf_read_minimal_symbols.

login
register
mail settings
Submitter Alex Lindsay
Date Aug. 8, 2017, 1:49 p.m.
Message ID <20170808134946.9701-1-alexlindsay239@gmail.com>
Download mbox | patch
Permalink /patch/21978/
State New
Headers show

Comments

Alex Lindsay - Aug. 8, 2017, 1:49 p.m.
The memory for synthsyms and synthsyms->name is allocated in elf64-x86-64.c
(elf_x86_64_get_synthetic_symtab). However, as shown by a valgrind memcheck,
this memory is not freed before synthsyms goes off the stack at the
termination of elf_read_minimal_symbols. This patch fixes that leak.
---
 gdb/ChangeLog | 5 +++++
 gdb/elfread.c | 3 +++
 2 files changed, 8 insertions(+)

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 92c573d76b..3246fea02c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@ 
+2017-08-08 Alex Lindsay <alexlindsay239@gmail.com>
+
+	* elfread.c (elf_read_minimal_symbols): Free synthsyms->name and
+	synthsyms
+
 2017-08-03  Tom Tromey  <tom@tromey.com>
 
 	* utils.c (make_cleanup_freeargv, do_freeargv, gdb_buildargv):
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.