From 493152cb4f287f9de3f03743349e911df9448e60 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Fri, 16 Oct 2009 07:14:43 +0000 Subject: PR binutils/10785 * coff-alpha.c (alpha_ecoff_get_elt_at_filepos): Don't bfd_alloc bim and bim->buffer. bfd_malloc instead. * peicode.h (pe_ILF_build_a_bfd): Similarly. (ILF_DATA_SIZE): Don't include bim. * opncls.c (bfd_close): Test bim->buffer non-NULL before freeing. --- bfd/peicode.h | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'bfd/peicode.h') diff --git a/bfd/peicode.h b/bfd/peicode.h index 8be8e70ed6..8f25ef9b33 100644 --- a/bfd/peicode.h +++ b/bfd/peicode.h @@ -422,7 +422,6 @@ pe_bfd_copy_private_bfd_data (bfd *ibfd, bfd *obfd) #define SIZEOF_ILF_SECTIONS (NUM_ILF_SECTIONS * sizeof (struct coff_section_tdata)) #define ILF_DATA_SIZE \ - sizeof (* vars.bim) \ + SIZEOF_ILF_SYMS \ + SIZEOF_ILF_SYM_TABLE \ + SIZEOF_ILF_NATIVE_SYMS \ @@ -780,15 +779,16 @@ pe_ILF_build_a_bfd (bfd * abfd, We are going to construct the contents of the BFD in memory, so allocate all the space that we will need right now. */ - ptr = (bfd_byte *) bfd_zalloc (abfd, (bfd_size_type) ILF_DATA_SIZE); - if (ptr == NULL) + vars.bim + = (struct bfd_in_memory *) bfd_malloc ((bfd_size_type) sizeof (*vars.bim)); + if (vars.bim == NULL) return FALSE; - /* Create a bfd_in_memory structure. */ - vars.bim = (struct bfd_in_memory *) ptr; + ptr = (bfd_byte *) bfd_zmalloc ((bfd_size_type) ILF_DATA_SIZE); vars.bim->buffer = ptr; vars.bim->size = ILF_DATA_SIZE; - ptr += sizeof (* vars.bim); + if (ptr == NULL) + goto error_return; /* Initialise the pointers to regions of the memory and the other contents of the pe_ILF_vars structure as well. */ @@ -842,7 +842,7 @@ pe_ILF_build_a_bfd (bfd * abfd, id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0); id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0); if (id4 == NULL || id5 == NULL) - return FALSE; + goto error_return; /* Fill in the contents of these sections. */ if (import_name_type == IMPORT_ORDINAL) @@ -869,7 +869,7 @@ pe_ILF_build_a_bfd (bfd * abfd, /* Create .idata$6 - the Hint Name Table. */ id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0); if (id6 == NULL) - return FALSE; + goto error_return; /* If necessary, trim the import symbol name. */ symbol = symbol_name; @@ -936,7 +936,7 @@ pe_ILF_build_a_bfd (bfd * abfd, /* Create the .text section. */ text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE); if (text == NULL) - return FALSE; + goto error_return; /* Copy in the jump code. */ memcpy (text->contents, jtab[i].data, jtab[i].size); @@ -985,10 +985,10 @@ pe_ILF_build_a_bfd (bfd * abfd, if ( ! bfd_set_start_address (abfd, (bfd_vma) 0) || ! bfd_coff_set_arch_mach_hook (abfd, & internal_f)) - return FALSE; + goto error_return; if (bfd_coff_mkobject_hook (abfd, (void *) & internal_f, NULL) == NULL) - return FALSE; + goto error_return; coff_data (abfd)->pe = 1; #ifdef THUMBPEMAGIC @@ -1050,6 +1050,12 @@ pe_ILF_build_a_bfd (bfd * abfd, abfd->flags |= HAS_SYMS; return TRUE; + + error_return: + if (vars.bim->buffer != NULL) + free (vars.bim->buffer); + free (vars.bim); + return FALSE; } /* We have detected a Image Library Format archive element. -- cgit v1.2.1