gdb/
authorJan Kratochvil <jan.kratochvil@redhat.com>
Fri, 19 Nov 2010 22:30:47 +0000 (22:30 +0000)
committerJan Kratochvil <jan.kratochvil@redhat.com>
Fri, 19 Nov 2010 22:30:47 +0000 (22:30 +0000)
Fix stale memory references.
* elfread.c (elf_symfile_read): Replace xmalloc by bfd_alloc, drop
xfree, new comment.

gdb/ChangeLog
gdb/elfread.c

index 39d48ef35ae48ddacf5945ba12e292c4ac9e901f..fcbd31d52a6193018e4a3dc4aed82e6081af7a92 100644 (file)
@@ -1,3 +1,9 @@
+2010-11-19  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+       Fix stale memory references.
+       * elfread.c (elf_symfile_read): Replace xmalloc by bfd_alloc, drop
+       xfree, new comment.
+
 2010-11-19  Jan Kratochvil  <jan.kratochvil@redhat.com>
            Tom Tromey  <tromey@redhat.com>
 
index 270f93feff851007d9fee57613741361959bff53..d607b874d35f4a92a16add9b303ee5454f1b83f0 100644 (file)
@@ -790,8 +790,14 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
 
   if (storage_needed > 0)
     {
-      dyn_symbol_table = (asymbol **) xmalloc (storage_needed);
-      make_cleanup (xfree, dyn_symbol_table);
+      /* Memory gets permanently referenced from ABFD after
+        bfd_get_synthetic_symtab so it must not get freed before ABFD gets.
+        It happens only in the case when elf_slurp_reloc_table sees
+        asection->relocation NULL.  Determining which section is asection is
+        done by _bfd_elf_get_synthetic_symtab which is all a bfd
+        implementation detail, though.  */
+
+      dyn_symbol_table = bfd_alloc (abfd, storage_needed);
       dynsymcount = bfd_canonicalize_dynamic_symtab (objfile->obfd,
                                                     dyn_symbol_table);