This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Call _close_and_cleanup in bfd_close_all_done


On Tue, Aug 29, 2017 at 11:49 PM, Alan Modra <amodra@gmail.com> wrote:
> On Tue, Aug 29, 2017 at 12:05:31PM -0700, H.J. Lu wrote:
>> OK for master?
>>
>> H.J.
>> ---
>>       PR binutils/22032
>>       * opncls.c (bfd_close_all_done): Call _close_and_cleanup.
>
> Please have a look at archive.c:_bfd_archive_close_and_cleanup and
> convince yourself that this change is safe.  archive_close_worker
> calls bfd_close_all_done.  I think it is OK, but I'd like to make sure
> you have put eyes on that code too.
>

We have


static int
archive_close_worker (void **slot, void *inf ATTRIBUTE_UNUSED)
{
  struct ar_cache *ent = (struct ar_cache *) *slot;

  bfd_close_all_done (ent->arbfd);
  return 1;
}

bfd_boolean
_bfd_archive_close_and_cleanup (bfd *abfd)
{
  if (bfd_read_p (abfd) && abfd->format == bfd_archive)
    {
      bfd *nbfd;
      bfd *next;
      htab_t htab;

      /* Close nested archives (if this bfd is a thin archive).  */
      for (nbfd = abfd->nested_archives; nbfd; nbfd = next)
        {
          next = nbfd->archive_next;
          bfd_close (nbfd);
        }

      htab = bfd_ardata (abfd)->cache;
      if (htab)
        {
          htab_traverse_noresize (htab, archive_close_worker, NULL);
          htab_delete (htab);
          bfd_ardata (abfd)->cache = NULL;
        }
    }

It is similar to

bfd_boolean
_bfd_archive_close_and_cleanup (bfd *abfd)
{
  if (bfd_read_p (abfd) && abfd->format == bfd_archive)
    {
      bfd *nbfd;
      bfd *next;
      htab_t htab;

      /* Close nested archives (if this bfd is a thin archive).  */
      for (nbfd = abfd->nested_archives; nbfd; nbfd = next)
        {
          next = nbfd->archive_next;
          bfd_close (nbfd);
        }

      htab = bfd_ardata (abfd)->cache;
      if (htab)
        {
          htab_traverse_noresize (htab, _bfd_archive_close_and_cleanup, NULL);
          htab_delete (htab);
          bfd_ardata (abfd)->cache = NULL;
        }
    }

Since an archive member can never be the archive which it is in,
it is safe.

-- 
H.J.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]