[PATCH v4 08/14] Use NT_FILE note section for reading core target memory

Tom Tromey tom@tromey.com
Tue Jul 21 18:21:35 GMT 2020


>>>>> "Kevin" == Kevin Buettner via Gdb-patches <gdb-patches@sourceware.org> writes:

>> > +	char *secname = (char *) bfd_alloc (bfd, strlen (secnamebuf) + 1);

>> SECNAME leaks if you throw here.  Use a unique pointer?

Kevin> It turns out that this code will leak even if the error pathway is not
Kevin> taken.  After studying bfd/section.c, it appears that nothing ever
Kevin> frees the section name.  bfd_make_section_anyway{,with_flags} is
Kevin> usually (though not always) called with a constant string like
Kevin> ".dynstr", ".plt", ".buildid", etc.  In those cases where it is passed
Kevin> a dynamically allocated string, I see no provision for freeing the
Kevin> section name.  I strongly suspect that there are leaks where this
Kevin> occurs.

bfd_alloc allocates on the BFD's objalloc (which is like an obstack, but
"optimized").  So, it's a leak in the "lingerer" sense (memory allocated
that isn't useful), but not in the ordinary sense, because it will be
freed when the BFD is closed.

Presumably if we had ASAN and/or valgrind annotations for obstack and
objalloc, this would show up as a real leak.  But we don't, so it won't.

I didn't look through BFD to see how section names might be allocated,
but if bfd_alloc is used, then it's fine.

Tom


More information about the Gdb-patches mailing list