aboutsummaryrefslogtreecommitdiff
path: root/bfd/vms-lib.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2019-09-18 10:34:46 +0930
committerAlan Modra <amodra@gmail.com>2019-09-18 21:32:51 +0930
commit90d92a632aaf75ce698335efeb383ddf785c12d8 (patch)
tree66d29393e4100245fd03bfd25d97e98861772cf2 /bfd/vms-lib.c
parent1bdd8facfbf6f94fa9603f528c7e8bdf91d90bfd (diff)
downloadgdb-90d92a632aaf75ce698335efeb383ddf785c12d8.zip
gdb-90d92a632aaf75ce698335efeb383ddf785c12d8.tar.gz
gdb-90d92a632aaf75ce698335efeb383ddf785c12d8.tar.bz2
Use bfd_set_filename more
Fixes a few leaks in bfd and ld. bfd/ * mach-o.c (bfd_mach_o_fat_member_init): Likewise. Replace xstrdup and xmalloc with bfd_strdup and bfd_malloc. Return an error status. Adjust calls. * vms-lib.c (_bfd_vms_lib_get_module): Test mhd->id earlier. Close bfd on failure. Replace xstrdup/bfd_alloc use with bfd_malloc. Use bfd_set_filename. gdb/ * solib-spu.c (spu_bfd_open): Use bfd_set_filename. * spu-linux-nat.c (spu_bfd_open): Likewise. ld/ * emultempl/pe.em (after_open): Use bfd_set_filename. * emultempl/pep.em (after_open): Use bfd_set_filename.
Diffstat (limited to 'bfd/vms-lib.c')
-rw-r--r--bfd/vms-lib.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/bfd/vms-lib.c b/bfd/vms-lib.c
index f238ba0..43addd4 100644
--- a/bfd/vms-lib.c
+++ b/bfd/vms-lib.c
@@ -1297,7 +1297,9 @@ _bfd_vms_lib_get_module (bfd *abfd, unsigned int modidx)
struct lib_tdata *tdata = bfd_libdata (abfd);
bfd *res;
file_ptr file_off;
- char *name;
+ const char *name;
+ char *newname;
+ size_t namelen;
/* Sanity check. */
if (modidx >= tdata->nbr_modules)
@@ -1335,18 +1337,22 @@ _bfd_vms_lib_get_module (bfd *abfd, unsigned int modidx)
if (bfd_bread (buf, tdata->mhd_size, abfd) != tdata->mhd_size)
return NULL;
+ mhd = (struct vms_mhd *) buf;
+ if (mhd->id != MHD__C_MHDID)
+ return NULL;
+
res = _bfd_create_empty_archive_element_shell (abfd);
if (res == NULL)
return NULL;
arelt = bfd_zmalloc (sizeof (*arelt));
if (arelt == NULL)
- return NULL;
+ {
+ bfd_close (res);
+ return NULL;
+ }
res->arelt_data = arelt;
/* Get info from mhd. */
- mhd = (struct vms_mhd *)buf;
- if (mhd->id != MHD__C_MHDID)
- return NULL;
if (tdata->mhd_size >= offsetof (struct vms_mhd, objstat) + 1)
res->selective_search = (mhd->objstat & MHD__M_SELSRC) ? 1 : 0;
res->mtime = vms_rawtime_to_time_t (mhd->datim);
@@ -1361,23 +1367,25 @@ _bfd_vms_lib_get_module (bfd *abfd, unsigned int modidx)
/* Set filename. */
name = tdata->modules[modidx].name;
+ namelen = strlen (name);
+ newname = bfd_malloc (namelen + 4 + 1);
+ if (newname == NULL)
+ {
+ bfd_close (res);
+ return NULL;
+ }
+ strcpy (newname, name);
switch (tdata->type)
{
case LBR__C_TYP_IOBJ:
case LBR__C_TYP_EOBJ:
/* For object archives, append .obj to mimic standard behaviour. */
- {
- size_t namelen = strlen (name);
- char *name1 = bfd_alloc (res, namelen + 4 + 1);
- memcpy (name1, name, namelen);
- strcpy (name1 + namelen, ".obj");
- name = name1;
- }
+ strcpy (newname + namelen, ".obj");
break;
default:
break;
}
- res->filename = xstrdup (name);
+ bfd_set_filename (res, newname);
tdata->cache[modidx] = res;