This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 9/9] do not malloc objfile->name
- From: Tom Tromey <tromey at redhat dot com>
- To: Pedro Alves <palves at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Tue, 21 Aug 2012 12:10:13 -0600
- Subject: Re: [PATCH 9/9] do not malloc objfile->name
- References: <87sjc946gb.fsf@fleche.redhat.com> <50180687.3020401@redhat.com>
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>> + if (objfile->obfd == NULL)
>> + {
>> + make_cleanup_bfd_unref (obfd);
>> + error (_("Can't open %s to read symbols."), objfile->name);
>> + }
[...]
>> - if (objfile->obfd == NULL)
>> - error (_("Can't open %s to read symbols."), objfile->name);
>> + objfile->name = bfd_get_filename (objfile->obfd);
Pedro> Took me a second to grok this change. The issue is that the
Pedro> lifetime of objfile-> name is now the BFD's lifetime, so we can't
Pedro> gdb_bfd_unref, and then use objfile->name in the error call. I
Pedro> think this deserves a small comment here, [...]
I changed the error to use 'obfd_filename'. I think this makes the
logic more obvious. I also added a comment:
if (objfile->obfd == NULL)
{
/* We have to make a cleanup and error here, rather
than erroring later, because once we unref OBFD,
OBFD_FILENAME will be freed. */
make_cleanup_bfd_unref (obfd);
error (_("Can't open %s to read symbols."), obfd_filename);
}
Tom