This is the mail archive of the
mailing list for the binutils project.
Re: bfd_get_full_section_contents memory leak, plus
>>>>> "Alan" == Alan Modra <firstname.lastname@example.org> 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.