This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
Re: Another BFD corefile issue
- To: ian at zembu dot com, gdb-patches at sourceware dot cygnus dot com
- Subject: Re: Another BFD corefile issue
- From: Michael Snyder <msnyder at cygnus dot com>
- Date: Thu, 06 Apr 2000 20:41:56 -0700
- Organization: Cygnus Solutions
- References: <000b01bfa03d$d541c610$22295dc6@snyder.cygnus.com>
- Reply-To: msnyder at cygnus dot com
Err, belay this patch. Doesn't work. I need to think
on it some more. Appologies for the disturbance.
Michael Snyder wrote:
>
> Also in elfcore.h, elf64_core_file_p may be called more than once from
> bfd_check_format_matches. If an earlier call matches, and a later call
> ALMOST matches, it may clobber the earlier allocated pointer for
> elf_obj_data. I believe that the elf_zalloc call for elf_obj_data is done
> too early, and I would like to move it down to just before it is actually
> needed -- thus reducing the chance of it being called on a near-match.
>
> The circumstance where this bites us is when elf64-sparc target comes
> before elf64-big.
>
> 2000-04-06 Michael Snyder <msnyder@seadog.cygnus.com>
>
> * elfcore.h (elf_core_file_p): delay allocating elf_obj_data
> until it is needed, reducing the chances of memory leaks or
> good data being clobbered unnecessarily.
>
> Index: elfcore.h
> ===================================================================
> RCS file: /cvs/src/src/bfd/elfcore.h,v
> retrieving revision 1.1.1.1
> diff -c -r1.1.1.1 elfcore.h
> *** elfcore.h 1999/05/03 07:28:57 1.1.1.1
> --- elfcore.h 2000/04/07 03:04:12
> ***************
> *** 124,137 ****
> goto wrong;
> }
>
> - /* Give abfd an elf_obj_tdata. */
> - elf_tdata (abfd) =
> - (struct elf_obj_tdata *) bfd_zalloc (abfd, sizeof (struct
> elf_obj_tdata));
> - if (elf_tdata (abfd) == NULL)
> - return NULL;
> -
> - /* FIXME: from here on down, "goto wrong" will leak memory. */
> -
> /* Swap in the rest of the header, now that we have the byte order. */
> i_ehdrp = elf_elfheader (abfd);
> elf_swap_ehdr_in (abfd, &x_ehdr, i_ehdrp);
> --- 124,129 ----
> ***************
> *** 191,196 ****
> --- 183,197 ----
> if (!i_phdrp)
> return NULL;
>
> + /* Give abfd an elf_obj_tdata. */
> + elf_tdata (abfd) =
> + (struct elf_obj_tdata *) bfd_zalloc (abfd, sizeof (struct
> elf_obj_tdata));
> + if (elf_tdata (abfd) == NULL)
> + return NULL;
> +
> + /* FIXME: from here on down, "goto wrong" will leak memory.
> + As will "return NULL". */
> +
> elf_tdata (abfd)->phdr = i_phdrp;
>
> /* Read and convert to internal form. */