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
On Thu, 16 Feb 2017 12:26:05 +0000
Pedro Alves <palves@redhat.com> wrote:
> 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;
> ^^^^^^
Indeed I did...
Sorry for the spam
Philipp