aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2024-12-10 16:02:53 +1030
committerAlan Modra <amodra@gmail.com>2024-12-12 16:04:51 +1030
commit6f0ab551876087d8bcce55beb55e58d72ae78d98 (patch)
tree56b3d2b22b0d5f6cdea812cccdcbbf55a746b8dc /bfd
parenteda87e58d12bfb73ff3e93b7e822488e578f7015 (diff)
downloadbinutils-6f0ab551876087d8bcce55beb55e58d72ae78d98.zip
binutils-6f0ab551876087d8bcce55beb55e58d72ae78d98.tar.gz
binutils-6f0ab551876087d8bcce55beb55e58d72ae78d98.tar.bz2
tdata related object_p tidy for various formats
The aout object_p function copies any existing tdata. Apparently this was done for hp300, an old target that is no longer supported. See commit ebd241352942. This isn't useful for current sources, nor is it necessary or useful any more to preserve tdata in object_p functions when a target doesn't match. When I was fixing this, I noticed some object_p functions rudely didn't release memory on failures, and others had nits in the bfd_error returns. * aoutx.h (some_aout_object_p): Don't restore previous tdata on failure. Don't copy any existing tdata. * archive.c (bfd_generic_archive_p): Don't restore previous tdata on failure. * pdp11.c (some_aout_object_p): Likewise. * coff-rs6000.c (_bfd_xcoff_archive_p): Allocate both artdata and extension in one call. Don't restore previous tdata on failure. * coff64-rs6000.c (xcoff64_archive_p): Likewise. * coffgen.c (coff_real_object_p): Don't restore previous tdata on failure. * ihex.c (ihex_object_p): Likewise. Simplify release of tdata on scan failure. * mach-o.c (bfd_mach_o_scan): Don't set tdata here. Do set error on read_command failure. (bfd_mach_o_header_p): Set tdata here, release on failure. Tidy bfd_error return values. (bfd_mach_o_fat_archive_p): Tidy error return values. * mmo.c (mmo_mkobject): Do not test current tdata. * pef.c (bfd_pef_scan_start_address): Set bfd_error on failure. (bfd_pef_scan): Don't set tdata here. (bfd_pef_object_p): Set tdata here, release on failure. Tidy bfd_error return values. (bfd_pef_xlib_object_p): Tidy bfd_error return values. * srec.c (srec_object_p): Don't restore previous tdata on failure. Do release tdata on failure. (symbolsrec_object_p): Likewise. * tekhex.c (tekhex_object_p): Don't ignore tekhex_mkobject failure. Release tdata on failure. * vms-alpha.c (alpha_vms_object_p): Don't restore previous tdata on failure. Simplify release of tdata. * xsym.c (bfd_sym_scan): Don't set tdata here. (bfd_sym_object_p): Set tdata here. Release on failure.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/aoutx.h12
-rw-r--r--bfd/archive.c9
-rw-r--r--bfd/coff-rs6000.c23
-rw-r--r--bfd/coff64-rs6000.c19
-rw-r--r--bfd/coffgen.c3
-rw-r--r--bfd/ihex.c11
-rw-r--r--bfd/mach-o.c31
-rw-r--r--bfd/mmo.c21
-rw-r--r--bfd/pdp11.c9
-rw-r--r--bfd/pef.c52
-rw-r--r--bfd/srec.c22
-rw-r--r--bfd/tekhex.c8
-rw-r--r--bfd/vms-alpha.c10
-rw-r--r--bfd/xsym.c7
14 files changed, 92 insertions, 145 deletions
diff --git a/bfd/aoutx.h b/bfd/aoutx.h
index 4c5be61..13a5d82 100644
--- a/bfd/aoutx.h
+++ b/bfd/aoutx.h
@@ -496,21 +496,14 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
struct internal_exec *execp,
bfd_cleanup (*callback_to_real_object_p) (bfd *))
{
- struct aout_data_struct *rawptr, *oldrawptr;
+ struct aout_data_struct *rawptr;
bfd_cleanup result;
- size_t amt = sizeof (*rawptr);
- rawptr = bfd_zalloc (abfd, amt);
+ rawptr = bfd_zalloc (abfd, sizeof (*rawptr));
if (rawptr == NULL)
return NULL;
-
- oldrawptr = abfd->tdata.aout_data;
abfd->tdata.aout_data = rawptr;
- /* Copy the contents of the old tdata struct. */
- if (oldrawptr != NULL)
- *abfd->tdata.aout_data = *oldrawptr;
-
abfd->tdata.aout_data->a.hdr = &rawptr->e;
/* Copy in the internal_exec struct. */
*(abfd->tdata.aout_data->a.hdr) = *execp;
@@ -675,7 +668,6 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
error_ret:
bfd_release (abfd, rawptr);
- abfd->tdata.aout_data = oldrawptr;
return NULL;
}
diff --git a/bfd/archive.c b/bfd/archive.c
index ad76739..12efa9d 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -894,7 +894,6 @@ _bfd_noarchive_openr_next_archived_file (bfd *archive,
bfd_cleanup
bfd_generic_archive_p (bfd *abfd)
{
- struct artdata *tdata_hold;
char armag[SARMAG + 1];
size_t amt;
@@ -914,15 +913,10 @@ bfd_generic_archive_p (bfd *abfd)
return NULL;
}
- tdata_hold = bfd_ardata (abfd);
-
amt = sizeof (struct artdata);
bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt);
if (bfd_ardata (abfd) == NULL)
- {
- bfd_ardata (abfd) = tdata_hold;
- return NULL;
- }
+ return NULL;
bfd_ardata (abfd)->first_file_filepos = SARMAG;
@@ -932,7 +926,6 @@ bfd_generic_archive_p (bfd *abfd)
if (bfd_get_error () != bfd_error_system_call)
bfd_set_error (bfd_error_wrong_format);
bfd_release (abfd, bfd_ardata (abfd));
- bfd_ardata (abfd) = tdata_hold;
return NULL;
}
diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c
index 09d868b..fff610d 100644
--- a/bfd/coff-rs6000.c
+++ b/bfd/coff-rs6000.c
@@ -1500,7 +1500,6 @@ _bfd_xcoff_slurp_armap (bfd *abfd)
bfd_cleanup
_bfd_xcoff_archive_p (bfd *abfd)
{
- struct artdata *tdata_hold;
char magic[SXCOFFARMAG];
size_t amt = SXCOFFARMAG;
@@ -1518,12 +1517,12 @@ _bfd_xcoff_archive_p (bfd *abfd)
return NULL;
}
- tdata_hold = bfd_ardata (abfd);
+ amt = sizeof (struct artdata) + sizeof (struct xcoff_artdata);
+ bfd_ardata (abfd) = bfd_zalloc (abfd, amt);
+ if (bfd_ardata (abfd) == NULL)
+ return NULL;
- amt = sizeof (struct artdata);
- bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt);
- if (bfd_ardata (abfd) == (struct artdata *) NULL)
- goto error_ret_restore;
+ bfd_ardata (abfd)->tdata = (void *) ((struct artdata *) bfd_ardata (abfd) + 1);
/* Now handle the two formats. */
if (magic[1] != 'b')
@@ -1546,11 +1545,6 @@ _bfd_xcoff_archive_p (bfd *abfd)
GET_VALUE_IN_FIELD (bfd_ardata (abfd)->first_file_filepos,
hdr.firstmemoff, 10);
- amt = sizeof (struct xcoff_artdata);
- bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
- if (bfd_ardata (abfd)->tdata == NULL)
- goto error_ret;
-
memcpy (&x_artdata (abfd)->u.hdr, &hdr, SIZEOF_AR_FILE_HDR);
}
else
@@ -1574,11 +1568,6 @@ _bfd_xcoff_archive_p (bfd *abfd)
(const char **) 0,
10);
- amt = sizeof (struct xcoff_artdata);
- bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
- if (bfd_ardata (abfd)->tdata == NULL)
- goto error_ret;
-
memcpy (&x_artdata (abfd)->u.bhdr, &hdr, SIZEOF_AR_FILE_HDR_BIG);
}
@@ -1586,8 +1575,6 @@ _bfd_xcoff_archive_p (bfd *abfd)
{
error_ret:
bfd_release (abfd, bfd_ardata (abfd));
- error_ret_restore:
- bfd_ardata (abfd) = tdata_hold;
return NULL;
}
diff --git a/bfd/coff64-rs6000.c b/bfd/coff64-rs6000.c
index 850a63c..2c3576a 100644
--- a/bfd/coff64-rs6000.c
+++ b/bfd/coff64-rs6000.c
@@ -1900,7 +1900,6 @@ xcoff64_slurp_armap (bfd *abfd)
static bfd_cleanup
xcoff64_archive_p (bfd *abfd)
{
- struct artdata *tdata_hold;
char magic[SXCOFFARMAG];
/* This is the new format. */
struct xcoff_ar_file_hdr_big hdr;
@@ -1931,30 +1930,22 @@ xcoff64_archive_p (bfd *abfd)
return NULL;
}
- tdata_hold = bfd_ardata (abfd);
+ amt = sizeof (struct artdata) + sizeof (struct xcoff_artdata);
+ bfd_ardata (abfd) = bfd_zalloc (abfd, amt);
+ if (bfd_ardata (abfd) == NULL)
+ return NULL;
- amt = sizeof (struct artdata);
- bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt);
- if (bfd_ardata (abfd) == (struct artdata *) NULL)
- goto error_ret_restore;
+ bfd_ardata (abfd)->tdata = (void *) ((struct artdata *) bfd_ardata (abfd) + 1);
bfd_ardata (abfd)->first_file_filepos = bfd_scan_vma (hdr.firstmemoff,
(const char **) NULL,
10);
- amt = sizeof (struct xcoff_artdata);
- bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
- if (bfd_ardata (abfd)->tdata == NULL)
- goto error_ret;
-
memcpy (&x_artdata (abfd)->u.bhdr, &hdr, SIZEOF_AR_FILE_HDR_BIG);
if (! xcoff64_slurp_armap (abfd))
{
- error_ret:
bfd_release (abfd, bfd_ardata (abfd));
- error_ret_restore:
- bfd_ardata (abfd) = tdata_hold;
return NULL;
}
diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index 5754dbb..dc5b0f4 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -307,7 +307,6 @@ coff_real_object_p (bfd *abfd,
flagword oflags = abfd->flags;
bfd_vma ostart = bfd_get_start_address (abfd);
void * tdata;
- void * tdata_save;
bfd_size_type readsize; /* Length of file_info. */
unsigned int scnhsz;
char *external_sections;
@@ -336,7 +335,6 @@ coff_real_object_p (bfd *abfd,
/* Set up the tdata area. ECOFF uses its own routine, and overrides
abfd->flags. */
- tdata_save = abfd->tdata.any;
tdata = bfd_coff_mkobject_hook (abfd, (void *) internal_f, (void *) internal_a);
if (tdata == NULL)
goto fail2;
@@ -375,7 +373,6 @@ coff_real_object_p (bfd *abfd,
_bfd_coff_free_symbols (abfd);
bfd_release (abfd, tdata);
fail2:
- abfd->tdata.any = tdata_save;
abfd->flags = oflags;
abfd->start_address = ostart;
return NULL;
diff --git a/bfd/ihex.c b/bfd/ihex.c
index 41eeb23..1dd1b2b 100644
--- a/bfd/ihex.c
+++ b/bfd/ihex.c
@@ -486,7 +486,6 @@ ihex_scan (bfd *abfd)
static bfd_cleanup
ihex_object_p (bfd *abfd)
{
- void * tdata_save;
bfd_byte b[9];
unsigned int i;
unsigned int type;
@@ -525,12 +524,12 @@ ihex_object_p (bfd *abfd)
}
/* OK, it looks like it really is an Intel Hex file. */
- tdata_save = abfd->tdata.any;
- if (! ihex_mkobject (abfd) || ! ihex_scan (abfd))
+ if (!ihex_mkobject (abfd))
+ return NULL;
+
+ if (!ihex_scan (abfd))
{
- if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL)
- bfd_release (abfd, abfd->tdata.any);
- abfd->tdata.any = tdata_save;
+ bfd_release (abfd, abfd->tdata.any);
return NULL;
}
diff --git a/bfd/mach-o.c b/bfd/mach-o.c
index 037718f..49ecd13 100644
--- a/bfd/mach-o.c
+++ b/bfd/mach-o.c
@@ -5263,8 +5263,6 @@ bfd_mach_o_scan (bfd *abfd,
break;
}
- abfd->tdata.mach_o_data = mdata;
-
bfd_mach_o_convert_architecture (header->cputype, header->cpusubtype,
&cpu_type, &cpu_subtype);
if (cpu_type == bfd_arch_unknown)
@@ -5320,7 +5318,10 @@ bfd_mach_o_scan (bfd *abfd,
}
if (!bfd_mach_o_read_command (abfd, cur, filesize))
- return false;
+ {
+ bfd_set_error (bfd_error_wrong_format);
+ return false;
+ }
}
}
@@ -5443,18 +5444,21 @@ bfd_mach_o_header_p (bfd *abfd,
mdata = (bfd_mach_o_data_struct *) bfd_zalloc (abfd, sizeof (*mdata));
if (mdata == NULL)
- goto fail;
+ return NULL;
+ abfd->tdata.mach_o_data = mdata;
+
mdata->hdr_offset = hdr_off;
if (!bfd_mach_o_scan (abfd, &header, mdata))
- goto wrong;
+ {
+ bfd_release (abfd, mdata);
+ return NULL;
+ }
return _bfd_no_cleanup;
wrong:
bfd_set_error (bfd_error_wrong_format);
-
- fail:
return NULL;
}
@@ -5541,7 +5545,11 @@ bfd_mach_o_fat_archive_p (bfd *abfd)
if (bfd_seek (abfd, 0, SEEK_SET) != 0
|| bfd_read (&hdr, sizeof (hdr), abfd) != sizeof (hdr))
- goto error;
+ {
+ if (bfd_get_error () != bfd_error_system_call)
+ goto wrong;
+ goto error;
+ }
adata = bfd_alloc (abfd, sizeof (mach_o_fat_data_struct));
if (adata == NULL)
@@ -5550,12 +5558,12 @@ bfd_mach_o_fat_archive_p (bfd *abfd)
adata->magic = bfd_getb32 (hdr.magic);
adata->nfat_arch = bfd_getb32 (hdr.nfat_arch);
if (adata->magic != 0xcafebabe)
- goto error;
+ goto wrong;
/* Avoid matching Java bytecode files, which have the same magic number.
In the Java bytecode file format this field contains the JVM version,
which starts at 43.0. */
if (adata->nfat_arch > 30)
- goto error;
+ goto wrong;
if (_bfd_mul_overflow (adata->nfat_arch,
sizeof (mach_o_fat_archentry), &amt))
@@ -5596,10 +5604,11 @@ bfd_mach_o_fat_archive_p (bfd *abfd)
return _bfd_no_cleanup;
+ wrong:
+ bfd_set_error (bfd_error_wrong_format);
error:
if (adata != NULL)
bfd_release (abfd, adata);
- bfd_set_error (bfd_error_wrong_format);
return NULL;
}
diff --git a/bfd/mmo.c b/bfd/mmo.c
index 8018fc7..6704bc2 100644
--- a/bfd/mmo.c
+++ b/bfd/mmo.c
@@ -565,21 +565,16 @@ mmo_mkobject (bfd *abfd)
{
mmo_init ();
- if (abfd->tdata.mmo_data == NULL)
- {
- time_t created;
-
- /* All fields are zero-initialized, so we don't have to explicitly
- initialize most. */
- tdata_type *tdata = (tdata_type *) bfd_zalloc (abfd, sizeof (tdata_type));
- if (tdata == NULL)
- return false;
+ /* All fields are zero-initialized, so we don't have to explicitly
+ initialize most. */
+ tdata_type *tdata = bfd_zalloc (abfd, sizeof (tdata_type));
+ if (tdata == NULL)
+ return false;
- created = time (NULL);
- bfd_put_32 (abfd, created, tdata->created);
+ time_t created = time (NULL);
+ bfd_put_32 (abfd, created, tdata->created);
- abfd->tdata.mmo_data = tdata;
- }
+ abfd->tdata.mmo_data = tdata;
return true;
}
diff --git a/bfd/pdp11.c b/bfd/pdp11.c
index ef86400..7099c0b 100644
--- a/bfd/pdp11.c
+++ b/bfd/pdp11.c
@@ -533,21 +533,15 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
struct internal_exec *execp,
bfd_cleanup (*callback_to_real_object_p) (bfd *))
{
- struct aout_data_struct *rawptr, *oldrawptr;
+ struct aout_data_struct *rawptr;
bfd_cleanup result;
size_t amt = sizeof (*rawptr);
rawptr = bfd_zalloc (abfd, amt);
if (rawptr == NULL)
return NULL;
-
- oldrawptr = abfd->tdata.aout_data;
abfd->tdata.aout_data = rawptr;
- /* Copy the contents of the old tdata struct. */
- if (oldrawptr != NULL)
- *abfd->tdata.aout_data = *oldrawptr;
-
abfd->tdata.aout_data->a.hdr = &rawptr->e;
/* Copy in the internal_exec struct. */
*(abfd->tdata.aout_data->a.hdr) = *execp;
@@ -710,7 +704,6 @@ NAME (aout, some_aout_object_p) (bfd *abfd,
error_ret:
bfd_release (abfd, rawptr);
- abfd->tdata.aout_data = oldrawptr;
return NULL;
}
diff --git a/bfd/pef.c b/bfd/pef.c
index 2d2f559..a82db90 100644
--- a/bfd/pef.c
+++ b/bfd/pef.c
@@ -483,7 +483,7 @@ bfd_pef_scan_start_address (bfd *abfd)
loaderlen = loadersec->size;
if (loaderlen < 56)
- goto error;
+ goto wrong;
if (bfd_seek (abfd, loadersec->filepos, SEEK_SET) != 0)
goto error;
loaderbuf = _bfd_malloc_and_read (abfd, loaderlen, loaderlen);
@@ -492,7 +492,7 @@ bfd_pef_scan_start_address (bfd *abfd)
ret = bfd_pef_parse_loader_header (abfd, loaderbuf, 56, &header);
if (ret < 0)
- goto error;
+ goto wrong;
if (header.main_section < 0)
goto end;
@@ -502,7 +502,7 @@ bfd_pef_scan_start_address (bfd *abfd)
break;
if (section == NULL)
- goto error;
+ goto wrong;
abfd->start_address = section->vma + header.main_offset;
@@ -510,6 +510,8 @@ bfd_pef_scan_start_address (bfd *abfd)
free (loaderbuf);
return 0;
+ wrong:
+ bfd_set_error (bfd_error_wrong_format);
error:
free (loaderbuf);
return -1;
@@ -559,8 +561,6 @@ bfd_pef_scan (bfd *abfd,
if (bfd_pef_scan_start_address (abfd) < 0)
return -1;
- abfd->tdata.pef_data = mdata;
-
return 0;
}
@@ -595,25 +595,26 @@ bfd_pef_object_p (bfd *abfd)
bfd_pef_data_struct *mdata;
if (bfd_pef_read_header (abfd, &header) != 0)
- goto wrong;
+ return NULL;
if (header.tag1 != BFD_PEF_TAG1 || header.tag2 != BFD_PEF_TAG2)
- goto wrong;
+ {
+ bfd_set_error (bfd_error_wrong_format);
+ return NULL;
+ }
mdata = (bfd_pef_data_struct *) bfd_zalloc (abfd, sizeof (*mdata));
if (mdata == NULL)
- goto fail;
+ return NULL;
if (bfd_pef_scan (abfd, &header, mdata))
- goto wrong;
+ {
+ bfd_release (abfd, mdata);
+ return NULL;
+ }
+ abfd->tdata.pef_data = mdata;
return _bfd_no_cleanup;
-
- wrong:
- bfd_set_error (bfd_error_wrong_format);
-
- fail:
- return NULL;
}
static int
@@ -1123,25 +1124,18 @@ bfd_pef_xlib_object_p (bfd *abfd)
{
bfd_pef_xlib_header header;
- if (bfd_pef_xlib_read_header (abfd, &header) != 0)
+ if (bfd_pef_xlib_read_header (abfd, &header) != 0
+ || header.tag1 != BFD_PEF_XLIB_TAG1
+ || (header.tag2 != BFD_PEF_VLIB_TAG2
+ && header.tag2 != BFD_PEF_BLIB_TAG2))
{
- bfd_set_error (bfd_error_wrong_format);
- return NULL;
- }
-
- if ((header.tag1 != BFD_PEF_XLIB_TAG1)
- || ((header.tag2 != BFD_PEF_VLIB_TAG2)
- && (header.tag2 != BFD_PEF_BLIB_TAG2)))
- {
- bfd_set_error (bfd_error_wrong_format);
+ if (bfd_get_error () != bfd_error_system_call)
+ bfd_set_error (bfd_error_wrong_format);
return NULL;
}
if (bfd_pef_xlib_scan (abfd, &header) != 0)
- {
- bfd_set_error (bfd_error_wrong_format);
- return NULL;
- }
+ return NULL;
return _bfd_no_cleanup;
}
diff --git a/bfd/srec.c b/bfd/srec.c
index 1534c81..565ce0a 100644
--- a/bfd/srec.c
+++ b/bfd/srec.c
@@ -642,7 +642,6 @@ srec_scan (bfd *abfd)
static bfd_cleanup
srec_object_p (bfd *abfd)
{
- void * tdata_save;
bfd_byte b[4];
srec_init ();
@@ -657,12 +656,12 @@ srec_object_p (bfd *abfd)
return NULL;
}
- tdata_save = abfd->tdata.any;
- if (! srec_mkobject (abfd) || ! srec_scan (abfd))
+ if (!srec_mkobject (abfd))
+ return NULL;
+
+ if (!srec_scan (abfd))
{
- if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL)
- bfd_release (abfd, abfd->tdata.any);
- abfd->tdata.any = tdata_save;
+ bfd_release (abfd, abfd->tdata.any);
return NULL;
}
@@ -677,7 +676,6 @@ srec_object_p (bfd *abfd)
static bfd_cleanup
symbolsrec_object_p (bfd *abfd)
{
- void * tdata_save;
char b[2];
srec_init ();
@@ -692,12 +690,12 @@ symbolsrec_object_p (bfd *abfd)
return NULL;
}
- tdata_save = abfd->tdata.any;
- if (! srec_mkobject (abfd) || ! srec_scan (abfd))
+ if (!srec_mkobject (abfd))
+ return NULL;
+
+ if (!srec_scan (abfd))
{
- if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL)
- bfd_release (abfd, abfd->tdata.any);
- abfd->tdata.any = tdata_save;
+ bfd_release (abfd, abfd->tdata.any);
return NULL;
}
diff --git a/bfd/tekhex.c b/bfd/tekhex.c
index b305c1f..00976b5 100644
--- a/bfd/tekhex.c
+++ b/bfd/tekhex.c
@@ -616,10 +616,14 @@ tekhex_object_p (bfd *abfd)
if (b[0] != '%' || !ISHEX (b[1]) || !ISHEX (b[2]) || !ISHEX (b[3]))
return NULL;
- tekhex_mkobject (abfd);
+ if (!tekhex_mkobject (abfd))
+ return NULL;
if (!pass_over (abfd, first_phase))
- return NULL;
+ {
+ bfd_release (abfd, abfd->tdata.tekhex_data);
+ return NULL;
+ }
return _bfd_no_cleanup;
}
diff --git a/bfd/vms-alpha.c b/bfd/vms-alpha.c
index df279bc..092798a 100644
--- a/bfd/vms-alpha.c
+++ b/bfd/vms-alpha.c
@@ -2790,7 +2790,6 @@ alpha_vms_free_private (bfd *abfd)
static bfd_cleanup
alpha_vms_object_p (bfd *abfd)
{
- void *tdata_save = abfd->tdata.any;
unsigned int test_len;
unsigned char *buf;
@@ -2798,10 +2797,7 @@ alpha_vms_object_p (bfd *abfd)
/* Allocate alpha-vms specific data. */
if (!vms_initialize (abfd))
- {
- abfd->tdata.any = tdata_save;
- return NULL;
- }
+ return NULL;
if (bfd_seek (abfd, 0, SEEK_SET))
goto error_ret;
@@ -2913,9 +2909,7 @@ alpha_vms_object_p (bfd *abfd)
error_ret:
alpha_vms_free_private (abfd);
- if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL)
- bfd_release (abfd, abfd->tdata.any);
- abfd->tdata.any = tdata_save;
+ bfd_release (abfd, abfd->tdata.any);
return NULL;
}
diff --git a/bfd/xsym.c b/bfd/xsym.c
index fe14acc..c0d4e44 100644
--- a/bfd/xsym.c
+++ b/bfd/xsym.c
@@ -2224,8 +2224,6 @@ bfd_sym_scan (bfd *abfd, bfd_sym_version version, bfd_sym_data_struct *mdata)
bfdsec->filepos = 0;
bfdsec->alignment_power = 0;
- abfd->tdata.sym_data = mdata;
-
return 0;
}
@@ -2233,7 +2231,7 @@ bfd_cleanup
bfd_sym_object_p (bfd *abfd)
{
bfd_sym_version version = -1;
- bfd_sym_data_struct *mdata;
+ bfd_sym_data_struct *mdata = NULL;
if (bfd_seek (abfd, 0, SEEK_SET) != 0
|| bfd_sym_read_version (abfd, &version) != 0)
@@ -2246,12 +2244,15 @@ bfd_sym_object_p (bfd *abfd)
if (bfd_sym_scan (abfd, version, mdata) != 0)
goto wrong;
+ abfd->tdata.sym_data = mdata;
return _bfd_no_cleanup;
wrong:
bfd_set_error (bfd_error_wrong_format);
fail:
+ if (mdata)
+ bfd_release (abfd, mdata);
return NULL;
}