Allocate minimal symbols with malloc
authorTom Tromey <tom@tromey.com>
Sat, 2 Mar 2019 19:29:48 +0000 (12:29 -0700)
committerTom Tromey <tom@tromey.com>
Fri, 15 Mar 2019 22:02:10 +0000 (16:02 -0600)
commit042d75e42c5572f333e0e06dabd3c5c4afab486c
tree32f8606eabd734669d29684d828893393fe29b51
parentdb92718b541158d4782dbc9f48401c20f2bbad6d
Allocate minimal symbols with malloc

Currently, minimal symbols are allocated on the per-BFD obstack.
However, it is also possible for multiple symbol readers to create
minimal symbols for a given objfile.  In this case, the minimal
symbols will be reallocated on the obstack, leading to some waste of
storage.

This is a memory leak, but I think it won't be caught by tools like
valgrind, because valgrind doesn't know about obstacks.

This patch fixes the problem by using malloc to allocate the storage
for minimal symbols.

gdb/ChangeLog
2019-03-15  Tom Tromey  <tom@tromey.com>

* objfiles.h (struct objfile_per_bfd_storage) <msymbols>: Now a
unique_xmalloc_ptr.
(objfile::msymbols_range::begin, objfile::msymbols_range::end):
Update.
* minsyms.c (lookup_minimal_symbol_by_pc_section)
(build_minimal_symbol_hash_tables)
(minimal_symbol_reader::install): Update.
gdb/ChangeLog
gdb/minsyms.c
gdb/objfiles.h