Fix crash in machoread.c

"./gdb ./gdb" was crashing for me on macOS.  Investigating showed that
macho_symfile_read was crashing because "symbol_table" was being freed
too soon.  This was introduced by my earlier patch to change
macho_symfile_read to use a std::vector.

Tested on macOS 10.13.5 using "./gdb ./gdb".  This should un-break
various already existing tests (testsuite/gdb.gdb at least), so no new
test case.

I'm checking this in as obvious.

gdb/ChangeLog
2018-06-27  Tom Tromey  <tom@tromey.com>

	* machoread.c (macho_symfile_read): Define "symbol_table" earlier.
This commit is contained in:
Tom Tromey
2018-06-27 13:06:33 -06:00
parent e76f78a052
commit 6317728958
2 changed files with 8 additions and 2 deletions

View File

@@ -793,6 +793,9 @@ macho_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
bfd *abfd = objfile->obfd;
long storage_needed;
std::vector<oso_el> oso_vector;
/* We have to hold on to the symbol table until the call to
macho_symfile_read_all_oso at the end of this function. */
gdb::def_vector<asymbol *> symbol_table;
/* Get symbols from the symbol table only if the file is an executable.
The symbol table of object files is not relocated and is expected to
@@ -812,8 +815,7 @@ macho_symfile_read (struct objfile *objfile, symfile_add_flags symfile_flags)
{
long symcount;
gdb::def_vector<asymbol *> symbol_table (storage_needed
/ sizeof (asymbol *));
symbol_table.resize (storage_needed / sizeof (asymbol *));
minimal_symbol_reader reader (objfile);