diff mbox

[12/14] Fix a memory leak and remove an unused member

Message ID 20200215165444.32653-13-tom@tromey.com
State New
Headers show

Commit Message

Tom Tromey Feb. 15, 2020, 4:54 p.m. UTC
I noticed that setup_type_unit_groups leaks the symtab vector -- it
allocates this with XNEWVEC, but from what I can tell, nothing frees
it.  This patch changes it to use XOBNEWVEC.

Also, the type_unit_unshareable::num_symtabs member is assigned but
never read.  So, this removes it.

2020-02-15  Tom Tromey  <tom@tromey.com>

	* dwarf2/read.h (struct type_unit_unshareable) <num_symtabs>:
	Remove.
	* dwarf2/read.c (dwarf2_cu::setup_type_unit_groups): Use
	XOBNEWVEC.
---
 gdb/ChangeLog     | 7 +++++++
 gdb/dwarf2/read.c | 7 ++++---
 gdb/dwarf2/read.h | 4 ----
 3 files changed, 11 insertions(+), 7 deletions(-)
diff mbox

Patch

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index d1c5bee1109..765fc4e8272 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -10973,9 +10973,10 @@  dwarf2_cu::setup_type_unit_groups (struct die_info *die)
 	 process_full_type_unit still needs to know if this is the first
 	 time.  */
 
-      tu_unshare->num_symtabs = line_header->file_names_size ();
-      tu_unshare->symtabs = XNEWVEC (struct symtab *,
-				     line_header->file_names_size ());
+      tu_unshare->symtabs
+	= XOBNEWVEC (&COMPUNIT_OBJFILE (cust)->objfile_obstack,
+		     struct symtab *,
+		     line_header->file_names_size ());
 
       auto &file_names = line_header->file_names ();
       for (i = 0; i < file_names.size (); ++i)
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index 8b2e8703aa0..18f3c264a0a 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -76,10 +76,6 @@  struct type_unit_unshareable
      so we create an essentially anonymous symtab as the compunit symtab.  */
   struct compunit_symtab *compunit_symtab = nullptr;
 
-  /* The number of symtabs from the line header.
-     The value here must match line_header.num_file_names.  */
-  unsigned int num_symtabs = 0;
-
   /* The symbol tables for this TU (obtained from the files listed in
      DW_AT_stmt_list).
      WARNING: The order of entries here must match the order of entries