[PATCH 9/9] do not malloc objfile->name
Pedro Alves
palves@redhat.com
Tue Jul 31 16:23:00 GMT 2012
On 07/30/2012 04:25 PM, Tom Tromey wrote:
> --- a/gdb/symfile.c
> +++ b/gdb/symfile.c
> @@ -2517,11 +2517,15 @@ reread_symbols (void)
> /* Open the new BFD before freeing the old one, so that
> the filename remains live. */
> objfile->obfd = gdb_bfd_open_maybe_remote (obfd_filename);
> + if (objfile->obfd == NULL)
> + {
> + make_cleanup_bfd_unref (obfd);
> + error (_("Can't open %s to read symbols."), objfile->name);
> + }
> gdb_bfd_unref (obfd);
> }
>
> - if (objfile->obfd == NULL)
> - error (_("Can't open %s to read symbols."), objfile->name);
> + objfile->name = bfd_get_filename (objfile->obfd);
Took me a second to grok this change. The issue is that the lifetime of
objfile->name is now the BFD's lifetime, so we can't gdb_bfd_unref, and then
use objfile->name in the error call. I think this deserves a small comment
here, because from this comment alone:
On 07/30/2012 04:25 PM, Tom Tromey wrote:>
> - /* The object file's name, tilde-expanded and absolute. Malloc'd; free it
> - if you free this struct. This pointer is never NULL. */
> + /* The object file's name, tilde-expanded and absolute. This
> + pointer is never NULL. This does not have to be freed; it is
> + guaranteed to have a lifetime at least as long as the objfile. */
>
one wouldn't infer that dependency.
--
Pedro Alves
More information about the Gdb-patches
mailing list