From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Michael Snyder" To: gdb@sources.redhat.com Subject: Another BFD corefile issue Date: Wed, 05 Sep 2001 00:12:00 -0000 Message-ID: <8cjj8a$p4d$1@cronkite.cygnus.com> X-SW-Source: 2001-09/msg00022.html Message-ID: <20010905001200.9oqsp2vg_N_xbu-_7qJdTfzOv7ax1kaxWzAUZKgxlVk@z> 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 * 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. */