bfd_get_full_section_contents memory leak, plus

Tom Tromey tromey@redhat.com
Thu Oct 18 01:22:00 GMT 2012


>>>>> "Alan" == Alan Modra <amodra@gmail.com> writes:

Tom> I noticed that bfd_get_full_section_contents has a memory leak.  If you
Tom> set BFD_DECOMPRESS on the BFD, then use bfd_get_full_section_contents to
Tom> read a compressed section, the uncompressed section data will be
Tom> malloc'd and stored as section->contents -- but nothing ever frees this.

Tom> My fix for this (appended) is to allocate the uncompressed data on the
Tom> BFD's objalloc.

Alan> Not OK.  bfd_malloc_and_get_section calls bfd_get_full_section_contents.
Alan> The data must be malloc'd because users of b_m_a_g_s free it.

I don't think that is the case -- my patch doesn't affect the 'ptr'
argument to bfd_get_full_section_contents -- but I will find another way
to avoid the leak.

I do see some frees of section->contents; I don't really see how those
can be reached via this code, but better safe I suppose.

I'd also appreciate a comment on my other question.

thanks,
Tom



More information about the Binutils mailing list