From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 82414 invoked by alias); 16 Feb 2017 12:26:11 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 82396 invoked by uid 89); 16 Feb 2017 12:26:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.0 required=5.0 tests=BAYES_20,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=UD:c_str, UD:ret.erase, philipp, retc_str X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 16 Feb 2017 12:26:09 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9BE45C04B95D; Thu, 16 Feb 2017 12:26:09 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1GCQ6CI013881; Thu, 16 Feb 2017 07:26:07 -0500 Subject: Re: [PATCH v3 5/6] Share fork_inferior et al with gdbserver To: Philipp Rudo References: <1482464361-4068-1-git-send-email-sergiodj@redhat.com> <20170208032257.15443-1-sergiodj@redhat.com> <20170208032257.15443-6-sergiodj@redhat.com> <20170216132338.69e7c464@ThinkPad> Cc: Sergio Durigan Junior , GDB Patches , Luis Machado From: Pedro Alves Message-ID: <69822b2e-e57e-3608-ed48-3c93842adcca@redhat.com> Date: Thu, 16 Feb 2017 12:26:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20170216132338.69e7c464@ThinkPad> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-02/txt/msg00437.txt.bz2 On 02/16/2017 12:23 PM, Philipp Rudo wrote: > On Wed, 15 Feb 2017 17:28:24 +0000 > Pedro Alves 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