From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 62077 invoked by alias); 18 Oct 2017 09:37:07 -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 61831 invoked by uid 89); 18 Oct 2017 09:37:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=no version=3.3.2 spammy=someday 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; Wed, 18 Oct 2017 09:37:01 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6735E13A53; Wed, 18 Oct 2017 09:36:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6735E13A53 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=palves@redhat.com Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 708CC6D7FA; Wed, 18 Oct 2017 09:36:58 +0000 (UTC) Subject: Re: [RFA 4/8] Make strip_bg_char return a unique_xmalloc_ptr To: Yao Qi , Tom Tromey References: <20171013205950.22943-1-tom@tromey.com> <20171013205950.22943-5-tom@tromey.com> <86shejwi6t.fsf@gmail.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <51ee0ee6-ed33-720d-6d9d-314dd750b52b@redhat.com> Date: Wed, 18 Oct 2017 09:37: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: <86shejwi6t.fsf@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-10/txt/msg00555.txt.bz2 On 10/16/2017 10:33 AM, Yao Qi wrote: > Tom Tromey writes: > >> - args = strip_bg_char (args, &async_exec); >> - args_chain = make_cleanup (xfree, args); >> + gdb::unique_xmalloc_ptr stripped = strip_bg_char (args, &async_exec); >> + args = stripped.get (); >> >> /* Do validation and preparation before possibly changing anything >> in the inferior. */ >> @@ -663,9 +663,6 @@ run_command_1 (char *args, int from_tty, enum run_how run_how) >> uiout->flush (); >> } >> >> - /* Done with ARGS. */ >> - do_cleanups (args_chain); >> - > > My concern is that we may leak something if some cleanups are registered > to the cleanup chain in the callees between make_cleanup and do_cleanups > here. However, I am not sure how to detect that. Personally, I'm not as much worried about cleanup leaks (because there's a TRY/CATCH at the top of the event loop, and TRY detects dangling cleanups via restore_my_cleanups), as about some cleanup installed in that chain, whose do_cleanups call must be run at the particular point it's being run. I've touched and moved around these cleanups in the past, and what thought might be worth a second look was whether prepare_execute_command or something around it was installing a cleanup. It isn't, and when I went looking a bit deeper I found 8bc2fe488957, where I had written: ~~~ attach_command installs a cleanup to re-enable stdin, but that's not necessary, as per the comment in prepare_execution_command. In any case, if someday it turns out necessary, we have a single place to install it now. ~~~ I think we're good. Found one nit: > @@ -1074,16 +1066,14 @@ step_1 (int skip_subroutines, int single_inst, char *count_string) ... > - count_string = strip_bg_char (count_string, &async_exec); > - args_chain = make_cleanup (xfree, count_string); > + gdb::unique_xmalloc_ptr stripped = > + strip_bg_char (count_string, &async_exec); = on next line. Thanks, Pedro Alves