public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Doug Evans <dje@google.com>
To: Hui Zhu <hui_zhu@mentor.com>
Cc: Tom Tromey <tromey@redhat.com>,
	Sergio Durigan Junior <sergiodj@redhat.com>,
		gdb-patches ml <gdb-patches@sourceware.org>,
		Edjunior Barbosa Machado <emachado@linux.vnet.ibm.com>,
	Nick Clifton <nickc@redhat.com>
Subject: Re: [PATCH] Remove gdb_bfd_stash_filename to fix crash with fix of binutils/11983
Date: Mon, 06 Jan 2014 17:12:00 -0000	[thread overview]
Message-ID: <CADPb22QzyGuTEERURKao991F4jttvMqSrxodQz3JU2MLNgQ=tg@mail.gmail.com> (raw)
In-Reply-To: <52CA8A7F.7090907@mentor.com>

On Mon, Jan 6, 2014 at 2:50 AM, Hui Zhu <hui_zhu@mentor.com> wrote:
> On 01/06/14 16:25, Tom Tromey wrote:
>>>>>>>
>>>>>>> "Hui" == Hui Zhu <hui_zhu@mentor.com> writes:
>>
>>
>> Hui> Thanks.  Post a new version.
>>
>> Thanks Hui.  This is definitely the direction I think the code should
>> go.
>>
>> Hui>  --- a/gdb/symfile-mem.c
>> Hui> +++ b/gdb/symfile-mem.c
>> Hui> @@ -104,11 +104,7 @@ symbol_file_add_from_memory (struct bfd
>> Hui>    if (name == NULL)
>> Hui>  nbfd-> filename = "shared object read from target memory";
>> Hui>    else
>> Hui> -    {
>> Hui> -      nbfd->filename = name;
>> Hui> -      gdb_bfd_stash_filename (nbfd);
>> Hui> -      xfree (name);
>> Hui> -    }
>> Hui> +    nbfd->filename = name;
>> Hui>   cleanup = make_cleanup_bfd_unref (nbfd);
>>
>> In this hunk there are two things to note.
>>
>> First, there is an earlier assignment to filename (in the context above)
>> that should use xstrdup.
>>
>> Second, the new assignment really ought to free the old nbfd->filename
>> first.
>
>
> I changed this part to:
>   xfree (bfd_get_filename (nbfd));
>   if (name == NULL)
>     nbfd->filename = xstrdup ("shared object read from target memory");
>   else
>     nbfd->filename = name;

I would prefer a new bfd routine to set the file name.
Then *it* is responsible for freeing the old name.

Any reason to not go that route?

> --- a/gdb/symfile-mem.c
> +++ b/gdb/symfile-mem.c
> @@ -101,14 +101,11 @@ symbol_file_add_from_memory (struct bfd
>      error (_("Failed to read a valid object file image from memory."));
>     gdb_bfd_ref (nbfd);
> +  xfree (bfd_get_filename (nbfd));

This line still screams of excessive chumminess with bfd.

>    if (name == NULL)
> -    nbfd->filename = "shared object read from target memory";
> +    nbfd->filename = xstrdup ("shared object read from target memory");
>    else
> -    {
>
> -      nbfd->filename = name;
> -      gdb_bfd_stash_filename (nbfd);
> -      xfree (name);
> -    }
> +    nbfd->filename = name;
>     cleanup = make_cleanup_bfd_unref (nbfd);
>

  parent reply	other threads:[~2014-01-06 17:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-04 16:23 Hui Zhu
2014-01-05 15:06 ` Sergio Durigan Junior
2014-01-05 15:48   ` Hui Zhu
2014-01-06  8:25     ` Tom Tromey
2014-01-06 10:50       ` Hui Zhu
2014-01-06 16:14         ` Tom Tromey
2014-01-06 17:12         ` Doug Evans [this message]
2014-01-06 21:07           ` Tom Tromey
2014-01-07 12:35             ` Pedro Alves
2014-01-07 13:55               ` Pedro Alves
2014-01-07 17:41               ` Tom Tromey
2014-01-07 19:54                 ` Pedro Alves

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='CADPb22QzyGuTEERURKao991F4jttvMqSrxodQz3JU2MLNgQ=tg@mail.gmail.com' \
    --to=dje@google.com \
    --cc=emachado@linux.vnet.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=hui_zhu@mentor.com \
    --cc=nickc@redhat.com \
    --cc=sergiodj@redhat.com \
    --cc=tromey@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).