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.
This commit is contained in:
parent
db92718b54
commit
042d75e42c
3 changed files with 26 additions and 19 deletions
|
@ -282,11 +282,9 @@ struct objfile_per_bfd_storage
|
|||
name and a zero value for the address. This makes it easy to walk
|
||||
through the array when passed a pointer to somewhere in the middle
|
||||
of it. There is also a count of the number of symbols, which does
|
||||
not include the terminating null symbol. The array itself, as well
|
||||
as all the data that it points to, should be allocated on the
|
||||
objfile_obstack for this file. */
|
||||
not include the terminating null symbol. */
|
||||
|
||||
minimal_symbol *msymbols = NULL;
|
||||
gdb::unique_xmalloc_ptr<minimal_symbol> msymbols;
|
||||
int minimal_symbol_count = 0;
|
||||
|
||||
/* The number of minimal symbols read, before any minimal symbol
|
||||
|
@ -375,13 +373,13 @@ struct objfile
|
|||
|
||||
minimal_symbol_iterator begin () const
|
||||
{
|
||||
return minimal_symbol_iterator (m_objfile->per_bfd->msymbols);
|
||||
return minimal_symbol_iterator (m_objfile->per_bfd->msymbols.get ());
|
||||
}
|
||||
|
||||
minimal_symbol_iterator end () const
|
||||
{
|
||||
return minimal_symbol_iterator
|
||||
(m_objfile->per_bfd->msymbols
|
||||
(m_objfile->per_bfd->msymbols.get ()
|
||||
+ m_objfile->per_bfd->minimal_symbol_count);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue