Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: "Michael Snyder" <msnyder@cygnus.com>
To: gdb@sources.redhat.com
Subject: Another BFD corefile issue
Date: Wed, 05 Sep 2001 00:12:00 -0000	[thread overview]
Message-ID: <8cjj8a$p4d$1@cronkite.cygnus.com> (raw)
Message-ID: <20010905001200.9oqsp2vg_N_xbu-_7qJdTfzOv7ax1kaxWzAUZKgxlVk@z> (raw)

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. */





             reply	other threads:[~2001-09-05  0:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-04-06 20:15 Michael Snyder [this message]
2001-09-05  0:12 ` Michael Snyder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='8cjj8a$p4d$1@cronkite.cygnus.com' \
    --to=msnyder@cygnus.com \
    --cc=gdb@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox