This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v3 5/6] Share fork_inferior et al with gdbserver
- From: Pedro Alves <palves at redhat dot com>
- To: Philipp Rudo <prudo at linux dot vnet dot ibm dot com>
- Cc: Sergio Durigan Junior <sergiodj at redhat dot com>, GDB Patches <gdb-patches at sourceware dot org>, Luis Machado <lgustavo at codesourcery dot com>
- Date: Thu, 16 Feb 2017 12:26:05 +0000
- Subject: Re: [PATCH v3 5/6] Share fork_inferior et al with gdbserver
- Authentication-results: sourceware.org; auth=none
- References: <1482464361-4068-1-git-send-email-sergiodj@redhat.com> <20170208032257.15443-1-sergiodj@redhat.com> <20170208032257.15443-6-sergiodj@redhat.com> <a8f84e39-cf7f-4778-1e0e-0dfe4f00f3da@redhat.com> <20170216132338.69e7c464@ThinkPad>
On 02/16/2017 12:23 PM, Philipp Rudo wrote:
> On Wed, 15 Feb 2017 17:28:24 +0000
> Pedro Alves <palves@redhat.com> wrote:
>
> [...]
>
>>> + ret.erase (ret.end () - 1);
>>> +
>>> + initialized_p = 1;
>>> }
>>>
>>> + return (char *) ret.c_str ();
>>
>> Can the function return const instead?
>
> No it can't. The function must either return the std::string or
> xstrdup (ret.c_str ()). 'std::string ret' is declared for this
> function only. Thus it is freed once the function returns ret.c_str ()
> leaving a dangling pointer.
Nope, it's not freed on return. You've missed the "static":
char *
get_exec_wrapper (void)
{
char **new_argv = argv;
static std::string ret;
^^^^^^
Thanks,
Pedro Alves