public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Tom Tromey <tromey@redhat.com>
Cc: Binutils Development <binutils@sourceware.org>
Subject: Re: [PATCH 3/5] remove deleted BFDs from the archive cache
Date: Fri, 17 Aug 2012 16:26:00 -0000	[thread overview]
Message-ID: <CAMe9rOoYZXRKbF2O5Vi2e9FTqTZdVSCfGjj1ZJ7rVg+f-_X73w@mail.gmail.com> (raw)
In-Reply-To: <87ipchlcua.fsf@fleche.redhat.com>

On Fri, Aug 17, 2012 at 9:09 AM, Tom Tromey <tromey@redhat.com> wrote:
> Alan> Tom said he'd look into fixing the leak this causes, so I'm happy
> Alan> to leave that to him.  :)
>
> Here's the patch.
>
> I think it would be good for someone to double check it.
>
> I wrote this patch by searching for all the places that could allocate
> an areltdata and changing them to use bfd_zmalloc.
>
> Then I examined all the users of bfd->arelt_data and all callers of
> bfd_read_ar_hdr (and _bfd_read_ar_hdr) to see how the data was used.
> This revealed a number of spots that used bfd_release to free this data.
>
> Finally, I added a free to _bfd_delete_bfd.
>
> I once again built ld and all the binutils programs with -lmcheck, and
> then ran the test suites.  These all passed.  I also ran a single 'ar'
> test (one that was failing yesterday) plus the new 'bfdtest1' test under
> valgrind.  These were also clean.
>
>
> I found a few oddities in BFD while working on this patch:
>
> * _bfd_get_elt_at_filepos can release new_areldata but still leave a
>   stale pointer in n_nfd->arelt_data.  I fixed this.  I am not sure if
>   this can ever result in a bug, but I think paranoia is preferable.
>
> * bfd_slurp_bsd_armap_f2 leaks 'mapdata' before the patch -- it frees it
>   on the error path but not on the normal path.  I fixed this.
>
> * _bfd_xcoff_read_ar_hdr currently allocates 'ret' with bfd_alloc.  I
>   think it should clear it instead; I did this.
>   Also, this function already assumes 'ret' is malloced, which is a
>   latent bug.
>
>
> One final note on arelt_data: right now it is a void* in the BFD.  It
> seems to me that it would be just as opaque, and more type-safe, to
> change the structure name to 'struct bfd_areltdata', then use this name
> in the BFD -- but leave the struct type incomplete so that library
> clients can't dereference it.
>
> Tom
>
> 2012-08-17  Tom Tromey  <tromey@redhat.com>
>
>         * vms-lib.c (_bfd_vms_lib_get_module): Use bfd_zmalloc for
>         areltdata.
>         * opncls.c (_bfd_delete_bfd): Free arelt_data.
>         * mach-o.c (bfd_mach_o_fat_member_init): Use bfd_zmalloc for
>         areltdata.
>         * ecoff.c (_bfd_ecoff_slurp_armap): Use free for mapdata.
>         * coff-rs6000.c (_bfd_xcoff_read_ar_hdr): Use bfd_zmalloc for
>         areltdata.
>         (xcoff_write_archive_contents_old): Likewise.
>         (xcoff_write_archive_contents_big): Likewise.
>         * archive64.c (bfd_elf64_archive_slurp_armap): Use free for
>         areltdata.
>         * archive.c (_bfd_generic_read_ar_hdr_mag): Use bfd_zmalloc and
>         free for areltdata.
>         (_bfd_get_elt_at_filepos): Likewise.  Clear n_nfd->arelt_data on
>         failure.
>         (do_slurp_bsd_armap): Use bfd_zmalloc and free for areltdata.
>         (do_slurp_coff_armap): Likewise.
>         (_bfd_slurp_extended_name_table): Likewise.
>         (bfd_slurp_bsd_armap_f2): Likewise.  Don't leak 'mapdata'.

I am not sure if we want to use bfd_zmalloc for all areltdata.  We
use bfd_ar_hdr_from_filesystem since we can't use member
objalloc nor archive objalloc.  In all other places, it is OK to
use archive objalloc for areltdata.

Do you have a testcase to show there is a problem?

Thanks.

-- 
H.J.

  reply	other threads:[~2012-08-17 16:14 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-03 14:55 Tom Tromey
2012-08-03 16:12 ` Alan Modra
2012-08-03 20:56   ` Tom Tromey
2012-08-08 22:47   ` Tom Tromey
2012-08-09 10:35     ` Alan Modra
2012-08-15 20:14       ` H.J. Lu
2012-08-15 21:30         ` Tom Tromey
2012-08-16 14:47           ` Alan Modra
2012-08-16 16:31             ` H.J. Lu
2012-08-16 18:14               ` Tom Tromey
2012-08-16 18:33                 ` H.J. Lu
2012-08-16 18:45                   ` Tom Tromey
2012-08-16 18:49                     ` H.J. Lu
2012-08-16 18:55                       ` Tom Tromey
2012-08-16 20:33                         ` Tom Tromey
2012-08-16 20:38                         ` H.J. Lu
2012-08-16 21:11                 ` H.J. Lu
2012-08-16 21:35                 ` H.J. Lu
2012-08-17  1:01                 ` Alan Modra
2012-08-17  1:06                   ` H.J. Lu
2012-08-17  2:44                     ` Alan Modra
2012-08-17  4:56                       ` Hans-Peter Nilsson
2012-08-17  5:04                         ` Alan Modra
2012-08-17  5:08                         ` H.J. Lu
2012-08-17  5:30                           ` H.J. Lu
2012-08-17  5:42                             ` H.J. Lu
2012-08-17  5:45                               ` H.J. Lu
2012-08-17  6:01                                 ` H.J. Lu
2012-08-17 13:10                                   ` H.J. Lu
2012-08-17 16:50                                     ` Hans-Peter Nilsson
2012-08-17 16:01                           ` Hans-Peter Nilsson
2012-08-17 16:10                             ` H.J. Lu
2012-08-17 16:14                               ` Hans-Peter Nilsson
2012-08-17 16:13                       ` Tom Tromey
2012-08-17 16:26                         ` H.J. Lu [this message]
2012-08-17 16:51                           ` Tom Tromey
2012-08-17 17:11                             ` H.J. Lu
2012-08-17 17:22                               ` Tom Tromey
2012-08-17 17:22                                 ` H.J. Lu
2012-08-17 19:03                                   ` Tom Tromey
2012-08-17 19:13                                     ` H.J. Lu
2012-08-18  4:37                         ` Alan Modra
2012-08-21  9:55                           ` Tom Tromey
2012-08-17  1:17                   ` Alan Modra
2012-08-17 15:36                   ` Tom Tromey
2012-08-17 15:38                     ` H.J. Lu
2012-08-17 15:43                       ` Tom Tromey
2012-08-17  0:48           ` H.J. Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMe9rOoYZXRKbF2O5Vi2e9FTqTZdVSCfGjj1ZJ7rVg+f-_X73w@mail.gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=tromey@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).