[PATCH v4 08/14] Use NT_FILE note section for reading core target memory
Kevin Buettner
kevinb@redhat.com
Tue Jul 14 07:53:55 GMT 2020
On Fri, 10 Jul 2020 21:08:27 +0100
Pedro Alves <pedro@palves.net> wrote:
> > + /* Make new BFD section. */
> > + char secnamebuf[64];
> > + sprintf (secnamebuf, "S%04d", num);
> > + char *secname = (char *) bfd_alloc (bfd, strlen (secnamebuf) + 1);
> > + if (secname == nullptr)
> > + error (_("Out of memory"));
> > + strcpy (secname, secnamebuf);
> > + asection *sec = bfd_make_section_anyway (bfd, secname);
> > + if (sec == nullptr)
> > + error (_("Can't make section"));
>
> SECNAME leaks if you throw here. Use a unique pointer?
It turns out that this code will leak even if the error pathway is not
taken. After studying bfd/section.c, it appears that nothing ever
frees the section name. bfd_make_section_anyway{,with_flags} is
usually (though not always) called with a constant string like
".dynstr", ".plt", ".buildid", etc. In those cases where it is passed
a dynamically allocated string, I see no provision for freeing the
section name. I strongly suspect that there are leaks where this
occurs.
It turns out that bfd_make_section_anyway() will create a new
section even if passed a name of an already existing section. I'm
experimenting with just passing in "load" as the name for each
needed section. So far, it seems to work.
Kevin
More information about the Gdb-patches
mailing list