diff --git a/bfd/opncls.c b/bfd/opncls.c index fdccba3..b9b3743 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -719,6 +719,17 @@ bfd_close (bfd *abfd) if (! BFD_SEND (abfd, _close_and_cleanup, (abfd))) return FALSE; + /* If ABFD is an archive bfd, or a bfd contained in an archive, + do any associated cleanup. This is necessary to avoid leaving + a dangling pointer somewhere. For instance, if ABFD is an object + contained in an archive, the archive's cache might have a reference + to ABFD that needs to be removed before we free ABFD. + + _bfd_archive_close_and_cleanup does nothing if ABFD is neither + an archive BFD nor a BFD of an object contained in an archive, + so it is safe to call it without checking the bfd kind. */ + _bfd_archive_close_and_cleanup (abfd); + ret = abfd->iovec->bclose (abfd); if (ret)