[PATCH v3 09/18] BFD: Prevent a crash on freeing a BFD's uninitialized section hash

Maciej W. Rozycki macro@redhat.com
Wed Jan 7 09:36:51 GMT 2026


On Tue, 9 Dec 2025, Jan Beulich wrote:

> > Ensure memory has been allocated for the section hash before freeing it 
> > in `bfd_preserve_restore' and `bfd_preserve_finish'.  It is not required 
> > in principle to only use these internal interfaces on BFDs whose section 
> > hash has been initialized and in particular building archive symbol maps 
> > on the fly would otherwise cause a crash in the latter function where a
> > BFD is passed whose data has been freed by `_bfd_free_cached_info'.
> 
> Wouldn't it make sense to have the function itself be more free()-like, in
> tolerating a NULL pointer (here not as function argument, but in the
> ->memory member)?

 This seems reasonable to me, but then I think it's `objalloc_free' that 
would preferably be such, as the underlying memory management call.  Then 
any higher-level handlers such as `bfd_hash_table_free' can be left alone.

 I have now posted a proposal[1]; hopefully it can go in right away if 
accepted, despite Stage 3, as libiberty is an auxiliary library and 
technically not a part of the compiler suite, plus the change should be 
trivially safe.  Or otherwise I have an alternative interim change for 
`bfd_hash_table_free'.

References:

[1] "libiberty: Make `objalloc_free' `free'-like WRT null pointer", 
    <https://inbox.sourceware.org/gcc-patches/9fe948aa-f55f-bbaf-1b67-e985a2c90db9@redhat.com/>.

  Maciej



More information about the Binutils mailing list