objalloc_free ((struct objalloc *) abfd->memory);
}
- free ((char *) bfd_get_filename (abfd));
free (abfd->arelt_data);
free (abfd);
}
/* PR 11983: Do not cache the original filename, but
rather make a copy - the original might go away. */
- nbfd->filename = bfd_strdup (filename);
- if (nbfd->filename == NULL)
+ if (!bfd_set_filename (nbfd, filename))
{
fclose (nbfd->iostream);
_bfd_delete_bfd (nbfd);
nbfd->iostream = stream;
/* PR 11983: Do not cache the original filename, but
rather make a copy - the original might go away. */
- nbfd->filename = bfd_strdup (filename);
- if (nbfd->filename == NULL)
+ if (!bfd_set_filename (nbfd, filename))
{
_bfd_delete_bfd (nbfd);
return NULL;
/* PR 11983: Do not cache the original filename, but
rather make a copy - the original might go away. */
- nbfd->filename = bfd_strdup (filename);
- if (nbfd->filename == NULL)
+ if (!bfd_set_filename (nbfd, filename))
{
_bfd_delete_bfd (nbfd);
return NULL;
/* PR 11983: Do not cache the original filename, but
rather make a copy - the original might go away. */
- nbfd->filename = bfd_strdup (filename);
- if (nbfd->filename == NULL)
+ if (!bfd_set_filename (nbfd, filename))
{
_bfd_delete_bfd (nbfd);
return NULL;
return NULL;
/* PR 11983: Do not cache the original filename, but
rather make a copy - the original might go away. */
- nbfd->filename = bfd_strdup (filename);
- if (nbfd->filename == NULL)
+ if (!bfd_set_filename (nbfd, filename))
{
_bfd_delete_bfd (nbfd);
return NULL;
if (!bfd_malloc_and_get_section (abfd, sect, &contents))
{
- if (contents != NULL)
- free (contents);
+ free (contents);
return NULL;
}
if (!bfd_malloc_and_get_section (abfd, sect, & contents))
{
- if (contents != NULL)
- free (contents);
+ free (contents);
return NULL;
}
if (!bfd_malloc_and_get_section (abfd, sect, & contents))
{
- if (contents != NULL)
- free (contents);
+ free (contents);
return NULL;
}
bfd_set_filename
SYNOPSIS
- void bfd_set_filename (bfd *abfd, char *filename);
+ const char *bfd_set_filename (bfd *abfd, const char *filename);
DESCRIPTION
- Set the filename of @var{abfd}. The old filename, if any, is freed.
- @var{filename} must be allocated using @code{xmalloc}. After
- this call, it is owned @var{abfd}.
+ Set the filename of @var{abfd}, copying the FILENAME parameter to
+ bfd_alloc'd memory owned by @var{abfd}. Returns a pointer the
+ newly allocated name, or NULL if the allocation failed.
*/
-void
-bfd_set_filename (bfd *abfd, char *filename)
+const char *
+bfd_set_filename (bfd *abfd, const char *filename)
{
- free ((char *) abfd->filename);
- abfd->filename = filename;
+ size_t len = strlen (filename) + 1;
+ char *n = bfd_alloc (abfd, len);
+ if (n)
+ {
+ memcpy (n, filename, len);
+ abfd->filename = n;
+ }
+ return n;
}