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 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.
Philipp