Re: [PATCH 02/10] clean up allocation of bfd filenames

Jan Kratochvil
2012-07-19T18:52:00Z

On Wed, 18 Jul 2012 21:34:10 +0200, Tom Tromey wrote:
> BFD requires the user to allocate the file name for a BFD.
> GDB does this inconsistently: sometimes the file name is malloc'd,
> sometimes not. Sometimes it is freed, sometimes not.
>
> This patch adds a new function that reallocated the BFD's filename
> using bfd_alloc. This ties the lifetime to the BFD and removes the
> need to free the filename when closing the BFD.
[...]
> +void
> +gdb_bfd_stash_filename (struct bfd *abfd)
> +{
> + char *name = bfd_get_filename (abfd);
> + char *data;
> +
> + data = bfd_alloc (abfd, strlen (name) + 1);
> + strcpy (data, name);
> +
> + /* Unwarranted chumminess with BFD. */
> + abfd->filename = data;
> +}

Would not it be worth propose this bfd filename memory storage globally in
bfd/ ?

Thanks,
Jan