This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v3 5/6] Share fork_inferior et al with gdbserver


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]