From d495ab0d843def702a6641fa4fc31708d7fc97b1 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Fri, 13 Jun 2014 19:11:39 +0930 Subject: Free linker hash table from bfd_close. Also tidies numerous error exit paths in various link_hash_table_create functions that failed to free memory. include/ * bfdlink.h (struct bfd_link_hash_table): Add hash_table_free field. bfd/ * archive.c: Include bfdlink.h. (_bfd_archive_close_and_cleanup): Call linker hash_table_free. * bfd.c (struct bfd): Add is_linker_output field. * elf-bfd.h (_bfd_elf_link_hash_table_free): Update prototype. * linker.c (_bfd_link_hash_table_init): Set up hash_table_free, link.hash and is_linker_output. (_bfd_generic_link_hash_table_free): Replace bfd_link_hash_table* param with bfd*. Assert is_linker_output and link.hash, and clear them before exit. * elf-m10300.c (elf32_mn10300_link_hash_table_free): Replace bfd_link_hash_table* param with bfd*. Hack is_linker_output and link.hash so we can free two linker hash tables. (elf32_mn10300_link_hash_table_create): Create static_hash_table first. Clean up on errors. Set hash_table_free pointer. * elf32-arm.c (elf32_arm_link_hash_table_free): Replace bfd_link_hash_table* param with bfd*. (elf32_arm_link_hash_table_create): Clean up on errors. Set hash_table_free pointer. * elf32-avr.c, * elf32-hppa.c, * elf32-i386.c, * elf32-m68hc1x.c, * elf32-m68k.c, * elf32-metag.c, * elf32-nios2.c, * elf32-xgate.c, * elf64-ia64-vms.c, * elf64-ppc.c, * elf64-x86-64.c, * elflink.c, * elfnn-aarch64.c, * elfnn-ia64.c, * elfxx-sparc.c, * xcofflink.c: Similarly. * simple.c (bfd_simple_get_relocated_section_contents): Save and clear link.next before creating linker hash table. Clean up on errors, and restore link.next on exit. * elf32-m68hc1x.h (m68hc11_elf_bfd_link_hash_table_free): Delete. * elf32-xgate.h (xgate_elf_bfd_link_hash_table_free): Delete. * elfxx-sparc.h (_bfd_sparc_elf_link_hash_table_free): Delete. * libcoff-in.h (_bfd_xcoff_bfd_link_hash_table_free): Delete. * hash.c (bfd_hash_table_init_n): Free table on error. * libbfd-in.h (_bfd_generic_link_hash_table_free): Update proto. * bfd-in2.h: Regenerate. * libbfd.h: Regenerate. * libcoff.h: Regenerate. --- bfd/elfnn-ia64.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'bfd/elfnn-ia64.c') diff --git a/bfd/elfnn-ia64.c b/bfd/elfnn-ia64.c index c87dd99..a8d8d0b 100644 --- a/bfd/elfnn-ia64.c +++ b/bfd/elfnn-ia64.c @@ -1414,10 +1414,10 @@ elfNN_ia64_local_dyn_info_free (void **slot, /* Destroy IA-64 linker hash table. */ static void -elfNN_ia64_link_hash_table_free (struct bfd_link_hash_table *hash) +elfNN_ia64_link_hash_table_free (bfd *obfd) { struct elfNN_ia64_link_hash_table *ia64_info - = (struct elfNN_ia64_link_hash_table *) hash; + = (struct elfNN_ia64_link_hash_table *) obfd->link.hash; if (ia64_info->loc_hash_table) { htab_traverse (ia64_info->loc_hash_table, @@ -1428,7 +1428,7 @@ elfNN_ia64_link_hash_table_free (struct bfd_link_hash_table *hash) objalloc_free ((struct objalloc *) ia64_info->loc_hash_memory); elf_link_hash_traverse (&ia64_info->root, elfNN_ia64_global_dyn_info_free, NULL); - _bfd_elf_link_hash_table_free (hash); + _bfd_elf_link_hash_table_free (obfd); } /* Create the derived linker hash table. The IA-64 ELF port uses this @@ -1458,10 +1458,10 @@ elfNN_ia64_hash_table_create (bfd *abfd) ret->loc_hash_memory = objalloc_create (); if (!ret->loc_hash_table || !ret->loc_hash_memory) { - free (ret); + elfNN_ia64_link_hash_table_free (abfd); return NULL; } - (void) elfNN_ia64_link_hash_table_free; + ret->root.root.hash_table_free = elfNN_ia64_link_hash_table_free; return &ret->root.root; } -- cgit v1.1