* archive.c (bfd_generic_archive_p): Likewise.
* coff-rs6000.c (_bfd_xcoff_archive_p): Likewise.
(_bfd_xcoff_archive_p): Use bfd_scan_vma in place of strtol.
* coff64-rs6000.c (xcoff64_slurp_armap): Likewise.
(xcoff64_archive_p): Likewise.
(xcoff64_openr_next_archived_file): Likewise.
(xcoff64_archive_p): Clean up tdata properly on error.
* coffgen.c (coff_real_object_p): Likewise.
(coff_object_p): Release filehdr and opthdr.
* ecoff.c (_bfd_ecoff_archive_p): Clean up tdata properly on error.
* ieee.c (ieee_archive_p): Likewise.
* ihex.c (ihex_object_p): Likewise.
(ihex_mkobject): Always allocate tdata.
* peicode.h (pe_ILF_object_p): Release bfd_alloc'd buffer on error.
* srec.c (srec_mkobject): Always allocate tdata.
(srec_object_p): Clean up tdata properly on error.
(symbolsrec_object_p): Likewise.
* versados.c (versados_object_p): Likewise.
* vms-misc.c (_bfd_vms_get_record): Use bfd_malloc instead of malloc,
and bfd_realloc instead of realloc.
(add_new_contents): Use bfd_alloc instead of bfd_malloc for sections.
* vms.c (vms_initialize): Always allocate tdata. Use bfd_alloc in
place of bfd_malloc, simplifying error freeing. Free hash table too.
(vms_object_p): Clean up tdata on error.
(vms_mkobject): Don't complain on stderr if vms_initialize fails.
(vms_close_and_cleanup): Adjust for bfd_alloc use.
2002-07-30 Alan Modra <amodra@bigpond.net.au>
+ * aoutx.h (some_aout_object_p): Clean up tdata properly on error.
+ * archive.c (bfd_generic_archive_p): Likewise.
+ * coff-rs6000.c (_bfd_xcoff_archive_p): Likewise.
+ (_bfd_xcoff_archive_p): Use bfd_scan_vma in place of strtol.
+ * coff64-rs6000.c (xcoff64_slurp_armap): Likewise.
+ (xcoff64_archive_p): Likewise.
+ (xcoff64_openr_next_archived_file): Likewise.
+ (xcoff64_archive_p): Clean up tdata properly on error.
+ * coffgen.c (coff_real_object_p): Likewise.
+ (coff_object_p): Release filehdr and opthdr.
+ * ecoff.c (_bfd_ecoff_archive_p): Clean up tdata properly on error.
+ * ieee.c (ieee_archive_p): Likewise.
+ * ihex.c (ihex_object_p): Likewise.
+ (ihex_mkobject): Always allocate tdata.
+ * peicode.h (pe_ILF_object_p): Release bfd_alloc'd buffer on error.
+ * srec.c (srec_mkobject): Always allocate tdata.
+ (srec_object_p): Clean up tdata properly on error.
+ (symbolsrec_object_p): Likewise.
+ * versados.c (versados_object_p): Likewise.
+ * vms-misc.c (_bfd_vms_get_record): Use bfd_malloc instead of malloc,
+ and bfd_realloc instead of realloc.
+ (add_new_contents): Use bfd_alloc instead of bfd_malloc for sections.
+ * vms.c (vms_initialize): Always allocate tdata. Use bfd_alloc in
+ place of bfd_malloc, simplifying error freeing. Free hash table too.
+ (vms_object_p): Clean up tdata on error.
+ (vms_mkobject): Don't complain on stderr if vms_initialize fails.
+ (vms_close_and_cleanup): Adjust for bfd_alloc use.
+
+2002-07-30 Alan Modra <amodra@bigpond.net.au>
+
* elfxx-ia64.c (elfNN_ia64_final_write_processing): Set e_flags.
2002-07-26 Chris Demetriou <cgd@broadcom.com>
obj_aout_sym_hashes (abfd) = NULL;
if (! NAME(aout,make_sections) (abfd))
- return NULL;
+ goto error_ret;
obj_datasec (abfd)->_raw_size = execp->a_data;
obj_bsssec (abfd)->_raw_size = execp->a_bss;
obj_textsec (abfd)->next = obj_datasec (abfd);
obj_datasec (abfd)->next = obj_bsssec (abfd);
#endif
+ return result;
}
- else
- {
- free (rawptr);
- abfd->tdata.aout_data = oldrawptr;
- }
- return result;
+
+ error_ret:
+ bfd_release (abfd, rawptr);
+ abfd->tdata.aout_data = oldrawptr;
+ return NULL;
}
/*
char armag[SARMAG + 1];
bfd_size_type amt;
- tdata_hold = abfd->tdata.aout_ar_data;
-
if (bfd_bread ((PTR) armag, (bfd_size_type) SARMAG, abfd) != SARMAG)
{
if (bfd_get_error () != bfd_error_system_call)
return 0;
#endif
- /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
- involves a cast, we can't do it as the left operand of assignment. */
- amt = sizeof (struct artdata);
- abfd->tdata.aout_ar_data = (struct artdata *) bfd_zalloc (abfd, amt);
+ tdata_hold = bfd_ardata (abfd);
+ amt = sizeof (struct artdata);
+ bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt);
if (bfd_ardata (abfd) == NULL)
- return NULL;
+ {
+ bfd_ardata (abfd) = tdata_hold;
+ return NULL;
+ }
bfd_ardata (abfd)->first_file_filepos = SARMAG;
bfd_ardata (abfd)->cache = NULL;
bfd_ardata (abfd)->extended_names = NULL;
bfd_ardata (abfd)->tdata = NULL;
- if (!BFD_SEND (abfd, _bfd_slurp_armap, (abfd)))
+ if (!BFD_SEND (abfd, _bfd_slurp_armap, (abfd))
+ || !BFD_SEND (abfd, _bfd_slurp_extended_name_table, (abfd)))
{
- bfd_release (abfd, bfd_ardata (abfd));
- abfd->tdata.aout_ar_data = tdata_hold;
if (bfd_get_error () != bfd_error_system_call)
bfd_set_error (bfd_error_wrong_format);
- return NULL;
- }
-
- if (!BFD_SEND (abfd, _bfd_slurp_extended_name_table, (abfd)))
- {
bfd_release (abfd, bfd_ardata (abfd));
- abfd->tdata.aout_ar_data = tdata_hold;
- if (bfd_get_error () != bfd_error_system_call)
- bfd_set_error (bfd_error_wrong_format);
+ bfd_ardata (abfd) = tdata_hold;
return NULL;
}
release bfd_ardata. FIXME. */
(void) bfd_close (first);
bfd_release (abfd, bfd_ardata (abfd));
- abfd->tdata.aout_ar_data = tdata_hold;
#endif
bfd_set_error (bfd_error_wrong_object_format);
+ bfd_ardata (abfd) = tdata_hold;
return NULL;
}
/* And we ought to close `first' here too. */
_bfd_xcoff_archive_p (abfd)
bfd *abfd;
{
+ struct artdata *tdata_hold;
char magic[SXCOFFARMAG];
- bfd_size_type amt;
+ bfd_size_type amt = SXCOFFARMAG;
- if (bfd_bread ((PTR) magic, (bfd_size_type) SXCOFFARMAG, abfd) != SXCOFFARMAG)
+ if (bfd_bread ((PTR) magic, amt, abfd) != amt)
{
if (bfd_get_error () != bfd_error_system_call)
bfd_set_error (bfd_error_wrong_format);
return NULL;
}
- /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
- involves a cast, we can't do it as the left operand of
- assignment. */
+ tdata_hold = bfd_ardata (abfd);
+
amt = sizeof (struct artdata);
- abfd->tdata.aout_ar_data = (struct artdata *) bfd_zalloc (abfd, amt);
+ bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt);
if (bfd_ardata (abfd) == (struct artdata *) NULL)
- return NULL;
+ goto error_ret_restore;
bfd_ardata (abfd)->cache = NULL;
bfd_ardata (abfd)->archive_head = NULL;
memcpy (hdr.magic, magic, SXCOFFARMAG);
/* Now read the rest of the file header. */
- if (bfd_bread ((PTR) &hdr.memoff,
- (bfd_size_type) SIZEOF_AR_FILE_HDR - SXCOFFARMAG, abfd)
- != SIZEOF_AR_FILE_HDR - SXCOFFARMAG)
+ amt = SIZEOF_AR_FILE_HDR - SXCOFFARMAG;
+ if (bfd_bread ((PTR) &hdr.memoff, amt, abfd) != amt)
{
if (bfd_get_error () != bfd_error_system_call)
bfd_set_error (bfd_error_wrong_format);
- return NULL;
+ goto error_ret;
}
bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
amt = SIZEOF_AR_FILE_HDR;
bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
if (bfd_ardata (abfd)->tdata == NULL)
- return NULL;
+ goto error_ret;
memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
}
memcpy (hdr.magic, magic, SXCOFFARMAG);
/* Now read the rest of the file header. */
- if (bfd_bread ((PTR) &hdr.memoff,
- (bfd_size_type) SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG, abfd)
- != SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG)
+ amt = SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG;
+ if (bfd_bread ((PTR) &hdr.memoff, amt, abfd) != amt)
{
if (bfd_get_error () != bfd_error_system_call)
bfd_set_error (bfd_error_wrong_format);
- return NULL;
+ goto error_ret;
}
- /* XXX This actually has to be a call to strtoll (at least on 32-bit
- machines) since the field width is 20 and there numbers with more
- than 32 bits can be represented. */
- bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
- (char **) NULL, 10);
+ bfd_ardata (abfd)->first_file_filepos = bfd_scan_vma (hdr.firstmemoff,
+ (const char **) 0,
+ 10);
amt = SIZEOF_AR_FILE_HDR_BIG;
bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
if (bfd_ardata (abfd)->tdata == NULL)
- return NULL;
+ goto error_ret;
memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
}
if (! _bfd_xcoff_slurp_armap (abfd))
{
+ error_ret:
bfd_release (abfd, bfd_ardata (abfd));
- abfd->tdata.aout_ar_data = (struct artdata *) NULL;
+ error_ret_restore:
+ bfd_ardata (abfd) = tdata_hold;
return NULL;
}
return true;
}
- off = strtol (xcoff_ardata_big (abfd)->symoff64, (char **) NULL, 10);
+ off = bfd_scan_vma (xcoff_ardata_big (abfd)->symoff64,
+ (const char **) NULL, 10);
if (off == 0)
{
bfd_has_map (abfd) = false;
if (bfd_seek (abfd, pos, SEEK_CUR) != 0)
return false;
- /* XXX This actually has to be a call to strtoll (at least on 32-bit
- machines) since the field width is 20 and there numbers with more
- than 32 bits can be represented. */
- sz = strtol (hdr.size, (char **) NULL, 10);
+ sz = bfd_scan_vma (hdr.size, (const char **) NULL, 10);
/* Read in the entire symbol table. */
contents = (bfd_byte *) bfd_alloc (abfd, sz);
xcoff64_archive_p (abfd)
bfd *abfd;
{
+ struct artdata *tdata_hold;
char magic[SXCOFFARMAG];
/* This is the new format. */
struct xcoff_ar_file_hdr_big hdr;
return NULL;
}
- /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
- involves a cast, we can't do it as the left operand of
- assignment. */
- amt = sizeof (struct artdata);
- abfd->tdata.aout_ar_data = (struct artdata *) bfd_zalloc (abfd, amt);
-
- if (bfd_ardata (abfd) == (struct artdata *) NULL)
- return NULL;
-
- bfd_ardata (abfd)->cache = NULL;
- bfd_ardata (abfd)->archive_head = NULL;
- bfd_ardata (abfd)->symdefs = NULL;
- bfd_ardata (abfd)->extended_names = NULL;
-
/* Copy over the magic string. */
memcpy (hdr.magic, magic, SXCOFFARMAG);
/* Now read the rest of the file header. */
- if (bfd_bread ((PTR) &hdr.memoff,
- (bfd_size_type) (SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG),
- abfd) != SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG)
+ amt = SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG;
+ if (bfd_bread ((PTR) &hdr.memoff, amt, abfd) != amt)
{
if (bfd_get_error () != bfd_error_system_call)
bfd_set_error (bfd_error_wrong_format);
return NULL;
}
- /* XXX This actually has to be a call to strtoll (at least on 32-bit
- machines) since the field width is 20 and there numbers with more
- than 32 bits can be represented. */
- bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
- (char **) NULL, 10);
+ tdata_hold = bfd_ardata (abfd);
+
+ 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)->cache = NULL;
+ bfd_ardata (abfd)->archive_head = NULL;
+ bfd_ardata (abfd)->symdefs = NULL;
+ bfd_ardata (abfd)->extended_names = NULL;
+ bfd_ardata (abfd)->first_file_filepos = bfd_scan_vma (hdr.firstmemoff,
+ (const char **) NULL,
+ 10);
amt = SIZEOF_AR_FILE_HDR_BIG;
bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
if (bfd_ardata (abfd)->tdata == NULL)
- return NULL;
+ goto error_ret;
memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
if (! xcoff64_slurp_armap (abfd))
{
+ error_ret:
bfd_release (abfd, bfd_ardata (abfd));
- abfd->tdata.aout_ar_data = (struct artdata *) NULL;
+ error_ret_restore:
+ bfd_ardata (abfd) = tdata_hold;
return NULL;
}
}
else
{
- /* XXX These actually have to be a calls to strtoll (at least
- on 32-bit machines) since the fields's width is 20 and
- there numbers with more than 32 bits can be represented. */
- filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
- 10);
+ filestart = bfd_scan_vma (arch_xhdr_big (last_file)->nextoff,
+ (const char **) NULL, 10);
}
- /* XXX These actually have to be calls to strtoll (at least on 32-bit
- machines) since the fields's width is 20 and there numbers with more
- than 32 bits can be represented. */
+
if (filestart == 0
- || filestart == strtol (xcoff_ardata_big (archive)->memoff,
- (char **) NULL, 10)
- || filestart == strtol (xcoff_ardata_big (archive)->symoff,
- (char **) NULL, 10))
+ || filestart == bfd_scan_vma (xcoff_ardata_big (archive)->memoff,
+ (const char **) NULL, 10)
+ || filestart == bfd_scan_vma (xcoff_ardata_big (archive)->symoff,
+ (const char **) NULL, 10))
{
bfd_set_error (bfd_error_no_more_archived_files);
return NULL;
flagword oflags = abfd->flags;
bfd_vma ostart = bfd_get_start_address (abfd);
PTR tdata;
+ PTR tdata_save;
bfd_size_type readsize; /* length of file_info */
unsigned int scnhsz;
char *external_sections;
/* 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, (PTR) internal_f, (PTR) internal_a);
if (tdata == NULL)
- return 0;
+ goto fail2;
scnhsz = bfd_coff_scnhsz (abfd);
readsize = (bfd_size_type) nscns * scnhsz;
fail:
bfd_release (abfd, tdata);
+ fail2:
+ abfd->tdata.any = tdata_save;
abfd->flags = oflags;
bfd_get_start_address (abfd) = ostart;
return (const bfd_target *) NULL;
filehdr = bfd_alloc (abfd, filhsz);
if (filehdr == NULL)
- return 0;
+ return NULL;
if (bfd_bread (filehdr, filhsz, abfd) != filhsz)
{
if (bfd_get_error () != bfd_error_system_call)
bfd_set_error (bfd_error_wrong_format);
- return 0;
+ bfd_release (abfd, filehdr);
+ return NULL;
}
bfd_coff_swap_filehdr_in (abfd, filehdr, &internal_f);
bfd_release (abfd, filehdr);
|| internal_f.f_opthdr > aoutsz)
{
bfd_set_error (bfd_error_wrong_format);
- return 0;
+ return NULL;
}
nscns = internal_f.f_nscns;
opthdr = bfd_alloc (abfd, aoutsz);
if (opthdr == NULL)
- return 0;
+ return NULL;
if (bfd_bread (opthdr, (bfd_size_type) internal_f.f_opthdr, abfd)
!= internal_f.f_opthdr)
{
- return 0;
+ bfd_release (abfd, opthdr);
+ return NULL;
}
bfd_coff_swap_aouthdr_in (abfd, opthdr, (PTR) &internal_a);
+ bfd_release (abfd, opthdr);
}
return coff_real_object_p (abfd, nscns, &internal_f,
char armag[SARMAG + 1];
bfd_size_type amt;
- tdata_hold = abfd->tdata.aout_ar_data;
-
if (bfd_bread ((PTR) armag, (bfd_size_type) SARMAG, abfd) != SARMAG)
{
if (bfd_get_error () != bfd_error_system_call)
return NULL;
}
- /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
- involves a cast, we can't do it as the left operand of
- assignment. */
- amt = sizeof (struct artdata);
- abfd->tdata.aout_ar_data = (struct artdata *) bfd_zalloc (abfd, amt);
+ tdata_hold = bfd_ardata (abfd);
+ amt = sizeof (struct artdata);
+ bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt);
if (bfd_ardata (abfd) == (struct artdata *) NULL)
{
- abfd->tdata.aout_ar_data = tdata_hold;
+ bfd_ardata (abfd) = tdata_hold;
return (const bfd_target *) NULL;
}
|| ! _bfd_ecoff_slurp_extended_name_table (abfd))
{
bfd_release (abfd, bfd_ardata (abfd));
- abfd->tdata.aout_ar_data = tdata_hold;
+ bfd_ardata (abfd) = tdata_hold;
return (const bfd_target *) NULL;
}
first = bfd_openr_next_archived_file (abfd, (bfd *) NULL);
if (first != NULL)
{
- boolean fail;
-
first->target_defaulted = false;
- fail = false;
if (bfd_check_format (first, bfd_object)
&& first->xvec != abfd->xvec)
{
+#if 0
+ /* We ought to close `first' here, but we can't, because
+ we have no way to remove it from the archive cache.
+ It's close to impossible to figure out when we can
+ release bfd_ardata. FIXME. */
(void) bfd_close (first);
bfd_release (abfd, bfd_ardata (abfd));
- abfd->tdata.aout_ar_data = tdata_hold;
- bfd_set_error (bfd_error_wrong_format);
+#endif
+ bfd_set_error (bfd_error_wrong_object_format);
+ bfd_ardata (abfd) = tdata_hold;
return NULL;
}
-
- /* We ought to close first here, but we can't, because we
- have no way to remove it from the archive cache. FIXME. */
+ /* And we ought to close `first' here too. */
}
}
abfd->tdata.ieee_ar_data = (ieee_ar_data_type *) bfd_alloc (abfd, amt);
if (!abfd->tdata.ieee_ar_data)
- goto error_return;
+ goto error_ret_restore;
ieee = IEEE_AR_DATA (abfd);
/* Ignore the return value here. It doesn't matter if we don't read
return abfd->xvec;
got_wrong_format_error:
- bfd_release (abfd, ieee);
- abfd->tdata.ieee_ar_data = save;
bfd_set_error (bfd_error_wrong_format);
-
error_return:
if (elts != NULL)
free (elts);
+ bfd_release (abfd, ieee);
+ error_ret_restore:
+ abfd->tdata.ieee_ar_data = save;
return NULL;
}
got_wrong_format:
bfd_set_error (bfd_error_wrong_format);
fail:
- (void) bfd_release (abfd, ieee);
+ bfd_release (abfd, ieee);
abfd->tdata.ieee_data = save;
return (const bfd_target *) NULL;
}
ihex_mkobject (abfd)
bfd *abfd;
{
- if (abfd->tdata.ihex_data == NULL)
- {
- struct ihex_data_struct *tdata;
- bfd_size_type amt = sizeof (struct ihex_data_struct);
+ struct ihex_data_struct *tdata;
+ bfd_size_type amt = sizeof (struct ihex_data_struct);
- tdata = (struct ihex_data_struct *) bfd_alloc (abfd, amt);
- if (tdata == NULL)
- return false;
- abfd->tdata.ihex_data = tdata;
- tdata->head = NULL;
- tdata->tail = NULL;
- }
+ tdata = (struct ihex_data_struct *) bfd_alloc (abfd, amt);
+ if (tdata == NULL)
+ return false;
+ abfd->tdata.ihex_data = tdata;
+ tdata->head = NULL;
+ tdata->tail = NULL;
return true;
}
ihex_object_p (abfd)
bfd *abfd;
{
+ PTR tdata_save;
bfd_byte b[9];
unsigned int i;
unsigned int type;
}
/* OK, it looks like it really is an Intel Hex file. */
- if (! ihex_mkobject (abfd)
- || ! ihex_scan (abfd))
- return NULL;
+ tdata_save = abfd->tdata.any;
+ if (! ihex_mkobject (abfd) || ! ihex_scan (abfd))
+ {
+ if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL)
+ bfd_release (abfd, abfd->tdata.any);
+ abfd->tdata.any = tdata_save;
+ return NULL;
+ }
return abfd->xvec;
}
return NULL;
if (bfd_bread (ptr, size, abfd) != size)
- return NULL;
+ {
+ bfd_release (abfd, ptr);
+ return NULL;
+ }
symbol_name = ptr;
source_dll = ptr + strlen (ptr) + 1;
(_("%s: string not null terminated in ILF object file."),
bfd_archive_filename (abfd));
bfd_set_error (bfd_error_malformed_archive);
-
+ bfd_release (abfd, ptr);
return NULL;
}
/* Now construct the bfd. */
if (! pe_ILF_build_a_bfd (abfd, magic, symbol_name,
source_dll, ordinal, types))
- return NULL;
+ {
+ bfd_release (abfd, ptr);
+ return NULL;
+ }
return abfd->xvec;
}
srec_mkobject (abfd)
bfd *abfd;
{
+ bfd_size_type amt;
+ tdata_type *tdata;
+
srec_init ();
- if (abfd->tdata.srec_data == NULL)
- {
- bfd_size_type amt = sizeof (tdata_type);
- tdata_type *tdata = (tdata_type *) bfd_alloc (abfd, amt);
- if (tdata == NULL)
- return false;
- abfd->tdata.srec_data = tdata;
- tdata->type = 1;
- tdata->head = NULL;
- tdata->tail = NULL;
- tdata->symbols = NULL;
- tdata->symtail = NULL;
- tdata->csymbols = NULL;
- }
+ amt = sizeof (tdata_type);
+ tdata = (tdata_type *) bfd_alloc (abfd, amt);
+ if (tdata == NULL)
+ return false;
+
+ abfd->tdata.srec_data = tdata;
+ tdata->type = 1;
+ tdata->head = NULL;
+ tdata->tail = NULL;
+ tdata->symbols = NULL;
+ tdata->symtail = NULL;
+ tdata->csymbols = NULL;
return true;
}
srec_object_p (abfd)
bfd *abfd;
{
+ PTR tdata_save;
bfd_byte b[4];
srec_init ();
return NULL;
}
- if (! srec_mkobject (abfd)
- || ! srec_scan (abfd))
- return NULL;
+ tdata_save = abfd->tdata.any;
+ if (! srec_mkobject (abfd) || ! srec_scan (abfd))
+ {
+ if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL)
+ bfd_release (abfd, abfd->tdata.any);
+ abfd->tdata.any = tdata_save;
+ return NULL;
+ }
if (abfd->symcount > 0)
abfd->flags |= HAS_SYMS;
symbolsrec_object_p (abfd)
bfd *abfd;
{
+ PTR tdata_save;
char b[2];
srec_init ();
return NULL;
}
- if (! srec_mkobject (abfd)
- || ! srec_scan (abfd))
- return NULL;
+ tdata_save = abfd->tdata.any;
+ if (! srec_mkobject (abfd) || ! srec_scan (abfd))
+ {
+ if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL)
+ bfd_release (abfd, abfd->tdata.any);
+ abfd->tdata.any = tdata_save;
+ return NULL;
+ }
if (abfd->symcount > 0)
abfd->flags |= HAS_SYMS;
{
struct ext_vheader ext;
unsigned char len;
+ tdata_type *tdata_save;
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
return NULL;
/* OK, looks like a record, build the tdata and read in. */
- if (!versados_mkobject (abfd)
- || !versados_scan (abfd))
- return NULL;
+ tdata_save = abfd->tdata.versados_data;
+ if (!versados_mkobject (abfd) || !versados_scan (abfd))
+ {
+ abfd->tdata.versados_data = tdata_save;
+ return NULL;
+ }
return abfd->xvec;
}
if (PRIV (buf_size) == 0)
{
+ bfd_size_type amt;
+
if (PRIV (is_vax))
{
- PRIV (vms_buf) = (unsigned char *) malloc (OBJ_S_C_MAXRECSIZ);
- PRIV (buf_size) = OBJ_S_C_MAXRECSIZ;
+ amt = OBJ_S_C_MAXRECSIZ;
PRIV (file_format) = FF_VAX;
}
else
- PRIV (vms_buf) = (unsigned char *) malloc (6);
+ amt = 6;
+ PRIV (vms_buf) = (unsigned char *) bfd_malloc (amt);
+ PRIV (buf_size) = amt;
}
vms_buf = PRIV (vms_buf);
if (vms_buf == 0)
- {
- bfd_set_error (bfd_error_no_memory);
- return -1;
- }
+ return -1;
switch (PRIV (file_format))
{
if (PRIV (is_vax))
{
PRIV (rec_length) = bfd_bread (vms_buf, (bfd_size_type) PRIV (buf_size),
- abfd);
+ abfd);
if (PRIV (rec_length) <= 0)
{
bfd_set_error (bfd_error_file_truncated);
{
/* extract vms record length */
- _bfd_vms_get_header_values (abfd, vms_buf+test_start, NULL,
+ _bfd_vms_get_header_values (abfd, vms_buf + test_start, NULL,
&PRIV (rec_length));
if (PRIV (rec_length) <= 0)
if (PRIV (rec_length) > PRIV (buf_size))
{
PRIV (vms_buf) = ((unsigned char *)
- realloc (vms_buf, (size_t) PRIV (rec_length)));
+ bfd_realloc (vms_buf,
+ (bfd_size_type) PRIV (rec_length)));
vms_buf = PRIV (vms_buf);
if (vms_buf == 0)
- {
- bfd_set_error (bfd_error_no_memory);
- return -1;
- }
+ return -1;
PRIV (buf_size) = PRIV (rec_length);
}
if (sptr != NULL)
return sptr;
- newptr = (vms_section *) bfd_malloc ((bfd_size_type) sizeof (vms_section));
+ newptr = (vms_section *) bfd_alloc (abfd,
+ (bfd_size_type) sizeof (vms_section));
if (newptr == (vms_section *) NULL)
return NULL;
newptr->contents = (unsigned char *) bfd_alloc (abfd, section->_raw_size);
int i;
bfd_size_type amt;
- if (abfd->tdata.any != 0)
- return true;
-
bfd_set_start_address (abfd, (bfd_vma) -1);
amt = sizeof (struct vms_private_data_struct);
- abfd->tdata.any = (struct vms_private_data_struct*) bfd_malloc (amt);
+ abfd->tdata.any = (struct vms_private_data_struct*) bfd_alloc (abfd, amt);
if (abfd->tdata.any == 0)
return false;
PRIV (sections) = NULL;
amt = sizeof (struct stack_struct) * STACKSIZE;
- PRIV (stack) = (struct stack_struct *) bfd_malloc (amt);
+ PRIV (stack) = (struct stack_struct *) bfd_alloc (abfd, amt);
if (PRIV (stack) == 0)
- {
- vms_init_no_mem1:
- free (abfd->tdata.any);
- abfd->tdata.any = 0;
- return false;
- }
+ goto error_ret1;
PRIV (stackptr) = 0;
amt = sizeof (struct bfd_hash_table);
- PRIV (vms_symbol_table) = (struct bfd_hash_table *) bfd_malloc (amt);
+ PRIV (vms_symbol_table) = (struct bfd_hash_table *) bfd_alloc (abfd, amt);
if (PRIV (vms_symbol_table) == 0)
- {
- vms_init_no_mem2:
- free (PRIV (stack));
- PRIV (stack) = 0;
- goto vms_init_no_mem1;
- }
+ goto error_ret1;
if (!bfd_hash_table_init (PRIV (vms_symbol_table), _bfd_vms_hash_newfunc))
- return false;
+ goto error_ret1;
amt = sizeof (struct location_struct) * LOCATION_SAVE_SIZE;
- PRIV (location_stack) = (struct location_struct *) bfd_malloc (amt);
+ PRIV (location_stack) = (struct location_struct *) bfd_alloc (abfd, amt);
if (PRIV (location_stack) == 0)
- {
- vms_init_no_mem3:
- free (PRIV (vms_symbol_table));
- PRIV (vms_symbol_table) = 0;
- goto vms_init_no_mem2;
- }
+ goto error_ret2;
for (i = 0; i < VMS_SECTION_COUNT; i++)
PRIV (vms_section_table)[i] = NULL;
- PRIV (output_buf) = (unsigned char *) malloc (MAX_OUTREC_SIZE);
+ amt = MAX_OUTREC_SIZE;
+ PRIV (output_buf) = (unsigned char *) bfd_alloc (abfd, amt);
if (PRIV (output_buf) == 0)
- {
- free (PRIV (location_stack));
- PRIV (location_stack) = 0;
- goto vms_init_no_mem3;
- }
+ goto error_ret2;
+
PRIV (push_level) = 0;
PRIV (pushed_size) = 0;
PRIV (length_pos) = 2;
PRIV (output_alignment) = 1;
return true;
+
+ error_ret2:
+ bfd_hash_table_free (PRIV (vms_symbol_table));
+ error_ret1:
+ bfd_release (abfd, abfd->tdata.any);
+ abfd->tdata.any = 0;
+ return false;
}
/* Fill symbol->section with section ptr
int prev_type;
const struct bfd_target *target_vector = 0;
const bfd_arch_info_type *arch = 0;
+ PTR tdata_save = abfd->tdata.any;
#if VMS_DEBUG
vms_debug (1, "vms_object_p(%p)\n", abfd);
#endif
if (!vms_initialize (abfd))
- {
- fprintf (stderr, "vms_initialize () failed !!\n");
- return 0;
- }
+ goto error_ret;
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET))
- {
- bfd_set_error (bfd_error_file_truncated);
- return 0;
- }
+ goto err_wrong_format;
prev_type = -1;
#if VMS_DEBUG
vms_debug (2, "next_record failed\n");
#endif
- bfd_set_error (bfd_error_wrong_format);
- return 0;
+ goto err_wrong_format;
}
if ((prev_type == EOBJ_S_C_EGSD)
#if VMS_DEBUG
vms_debug (2, "vms_fixup_sections failed\n");
#endif
- bfd_set_error (bfd_error_wrong_format);
- return 0;
+ goto err_wrong_format;
}
}
#if VMS_DEBUG
vms_debug (2, "slurp type %d failed with %d\n", prev_type, err);
#endif
- bfd_set_error (bfd_error_wrong_format);
- return 0;
+ goto err_wrong_format;
}
}
while ((prev_type != EOBJ_S_C_EEOM) && (prev_type != OBJ_S_C_EOM) && (prev_type != OBJ_S_C_EOMW));
#if VMS_DEBUG
vms_debug (2, "vms_fixup_sections failed\n");
#endif
- bfd_set_error (bfd_error_wrong_format);
- return 0;
+ goto err_wrong_format;
}
/* set arch_info to vax */
#if VMS_DEBUG
vms_debug (2, "arch not found\n");
#endif
- bfd_set_error (bfd_error_wrong_format);
- return 0;
+ goto err_wrong_format;
}
abfd->arch_info = arch;
return target_vector;
+
+ err_wrong_format:
+ bfd_set_error (bfd_error_wrong_format);
+ error_ret:
+ if (abfd->tdata.any != tdata_save && abfd->tdata.any != NULL)
+ bfd_release (abfd, abfd->tdata.any);
+ abfd->tdata.any = tdata_save;
+ return NULL;
}
/* Check the format for a file being read.
#endif
if (!vms_initialize (abfd))
- {
- fprintf (stderr, "vms_initialize () failed !!\n");
- return 0;
- }
+ return 0;
{
#ifdef __VAX
vms_close_and_cleanup (abfd)
bfd *abfd;
{
- asection *sec;
- vms_section *es, *es1;
- int i;
-
#if VMS_DEBUG
vms_debug (1, "vms_close_and_cleanup(%p)\n", abfd);
#endif
return true;
if (PRIV (vms_buf) != NULL)
- {
- free (PRIV (vms_buf));
- PRIV (vms_buf) = NULL;
- }
- PRIV (buf_size) = 0;
-
- if (PRIV (output_buf) != 0)
- {
- free (PRIV (output_buf));
- PRIV (output_buf) = 0;
- }
-
- sec = abfd->sections;
- while (sec != NULL)
- {
- if (sec->contents)
- free (sec->contents);
- sec = sec->next;
- }
+ free (PRIV (vms_buf));
if (PRIV (sections) != NULL)
- {
- free (PRIV (sections));
- PRIV (sections) = NULL;
- }
+ free (PRIV (sections));
if (PRIV (vms_symbol_table))
- {
- bfd_hash_table_free (PRIV (vms_symbol_table));
- PRIV (vms_symbol_table) = 0;
- }
-
- if (PRIV (stack))
- {
- free (PRIV (stack));
- PRIV (stack) = 0;
- }
-
- if (PRIV (location_stack))
- {
- free (PRIV (location_stack));
- PRIV (location_stack) = 0;
- }
-
- for (i = 0; i < VMS_SECTION_COUNT; i++)
- {
- es = PRIV (vms_section_table)[i];
- while (es != NULL)
- {
- es1 = es->next;
- free (es);
- es = es1;
- }
- PRIV (vms_section_table)[i] = NULL;
- }
+ bfd_hash_table_free (PRIV (vms_symbol_table));
- free (abfd->tdata.any);
+ bfd_release (abfd, abfd->tdata.any);
abfd->tdata.any = NULL;
return true;