From 515ef31dec50185cc5d8a6f88b51832bfd259e87 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Wed, 20 Feb 2008 17:42:36 +0000 Subject: PR 868 * libbfd.c (bfd_realloc_or_free): New function. Performs like bfd_realloc, but if the (re)allocation fails, the pointer is freed. * libbfd-in.h: Prototype. * libbfd.h: Regenerate. * bfdio.c (bfd_bwrite): Use the new function. (bfd_seek): Likewise. * bfdwin.c:(bfd_get_file_window): Likewise. * elf-strtab.c (_bfd_elf_strtab_add): Likewise. * elf32-ppc.c (ppc_elf_relax_section): Likewise. * elf32-xtensa.c (vsprintf_msg): Likewise. * mach-o.c (bfd_mach_o_core_fetch_environment): Likewise. * stabs.c (_bfd_link_seciton_stabs): Likewise. * vms-misc.c (_bfd_vms_get_record): Likewise. * vms-tir.c (check_section): Likewise. * vms.c (vms_new_section_hook): Likewise. * elf32-arm.c (elf32_arm_section_map_add): Check that the allocation of sec_data->map succeeded before using it. * elflink.c (elf_link_output_sym): Do not overwrite finfo-> symshndxbuf until it is known that the reallocation succeeded. --- bfd/bfdwin.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bfd/bfdwin.c') diff --git a/bfd/bfdwin.c b/bfd/bfdwin.c index a44265e..dfe89cb 100644 --- a/bfd/bfdwin.c +++ b/bfd/bfdwin.c @@ -1,5 +1,5 @@ /* Support for memory-mapped windows into a BFD. - Copyright 1995, 1996, 2001, 2002, 2003, 2005, 2007 + Copyright 1995, 1996, 2001, 2002, 2003, 2005, 2007, 2008 Free Software Foundation, Inc. Written by Cygnus Support. @@ -224,16 +224,16 @@ bfd_get_file_window (bfd *abfd, if (debug_windows) fprintf (stderr, "\n\t%s(%6ld)", i->data ? "realloc" : " malloc", (long) size_to_alloc); - i->data = bfd_realloc (i->data, size_to_alloc); + i->data = bfd_realloc_or_free (i->data, size_to_alloc); if (debug_windows) fprintf (stderr, "\t-> %p\n", i->data); - i->refcount = 1; if (i->data == NULL) { if (size_to_alloc == 0) return TRUE; return FALSE; } + i->refcount = 1; if (bfd_seek (abfd, offset, SEEK_SET) != 0) return FALSE; i->size = bfd_bread (i->data, size, abfd); -- cgit v1.1