diff mbox

[RFA,16/22] Use std::vector in elf_read_minimal_symbols

Message ID 1474949330-4307-17-git-send-email-tom@tromey.com
State New
Headers show

Commit Message

Tom Tromey Sept. 27, 2016, 4:08 a.m. UTC
This changes elf_read_minimal_symbols to use std::vector rather than
an explicit allocation.  This removes a cleanup.

2016-09-26  Tom Tromey  <tom@tromey.com>

	* elfread.c (elf_read_minimal_symbols): Use std::vector.
---
 gdb/ChangeLog |  4 ++++
 gdb/elfread.c | 11 +++--------
 2 files changed, 7 insertions(+), 8 deletions(-)

Comments

Pedro Alves Oct. 9, 2016, 5:30 p.m. UTC | #1
On 09/27/2016 05:08 AM, Tom Tromey wrote:
> This changes elf_read_minimal_symbols to use std::vector rather than
> an explicit allocation.  This removes a cleanup.

LGTM, though same comment about unique_ptr applies.  (I'll stop
saying that in follow up patches, even it would apply).

Thanks,
Pedro Alves
diff mbox

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 3744387..770a96f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@ 
 2016-09-26  Tom Tromey  <tom@tromey.com>
 
+	* elfread.c (elf_read_minimal_symbols): Use std::vector.
+
+2016-09-26  Tom Tromey  <tom@tromey.com>
+
 	* machoread.c (macho_symfile_read_all_oso): Use std::string.
 
 2016-09-26  Tom Tromey  <tom@tromey.com>
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 09ac507..ad38bfe 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -47,6 +47,7 @@ 
 #include "build-id.h"
 #include "location.h"
 #include "auxv.h"
+#include <vector>
 
 extern void _initialize_elfread (void);
 
@@ -1024,7 +1025,6 @@  elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
 			  const struct elfinfo *ei)
 {
   bfd *synth_abfd, *abfd = objfile->obfd;
-  struct cleanup *back_to;
   long symcount = 0, dynsymcount = 0, synthcount, storage_needed;
   asymbol **symbol_table = NULL, **dyn_symbol_table = NULL;
   asymbol *synthsyms;
@@ -1053,7 +1053,6 @@  elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
     }
 
   scoped_minimal_symbol_reader reader (objfile);
-  back_to = make_cleanup (null_cleanup, NULL);
 
   /* Allocate struct to keep track of the symfile.  */
   dbx = XCNEW (struct dbx_symfile_info);
@@ -1135,16 +1134,13 @@  elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
 					 &synthsyms);
   if (synthcount > 0)
     {
-      asymbol **synth_symbol_table;
       long i;
 
-      make_cleanup (xfree, synthsyms);
-      synth_symbol_table = XNEWVEC (asymbol *, synthcount);
+      std::vector<asymbol *> synth_symbol_table (synthcount);
       for (i = 0; i < synthcount; i++)
 	synth_symbol_table[i] = synthsyms + i;
-      make_cleanup (xfree, synth_symbol_table);
       elf_symtab_read (reader, objfile, ST_SYNTHETIC, synthcount,
-		       synth_symbol_table, 1);
+		       synth_symbol_table.data (), 1);
     }
 
   /* Install any minimal symbols that have been collected as the current
@@ -1154,7 +1150,6 @@  elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
      which will do this.  */
 
   reader.install ();
-  do_cleanups (back_to);
 
   if (symtab_create_debug)
     fprintf_unfiltered (gdb_stdlog, "Done reading minimal symbols.\n");