From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 7CF703857C4A for ; Sun, 9 Aug 2020 22:45:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7CF703857C4A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 144A71E554; Sun, 9 Aug 2020 18:45:38 -0400 (EDT) Subject: Re: [PP?] [PATCH 2/6] Use new/delete for do_module_cleanup To: Tom Tromey , gdb-patches@sourceware.org References: <20200809135258.8207-1-tom@tromey.com> <20200809135258.8207-3-tom@tromey.com> From: Simon Marchi Message-ID: <2f2630fa-fb4f-41ee-403b-92c7bde8ffe6@simark.ca> Date: Sun, 9 Aug 2020 18:45:28 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200809135258.8207-3-tom@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Aug 2020 22:45:39 -0000 On 2020-08-09 9:52 a.m., Tom Tromey wrote: > This changes do_module_cleanup to use new and delete. It also removes > the use of the struct hack from this object -- this requires more > allocations for now, but this will be removed in a subsequent patch. > > gdb/ChangeLog > 2020-08-08 Tom Tromey > > * compile/compile-object-run.c (struct do_module_cleanup): Add > constructor, destructor. > : Don't use struct hack. > (do_module_cleanup): Use delete. > (compile_object_run): Use new. > --- > gdb/ChangeLog | 8 ++++++++ > gdb/compile/compile-object-run.c | 24 ++++++++++++++++-------- > 2 files changed, 24 insertions(+), 8 deletions(-) > > diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c > index a2f39900053..4a18655d488 100644 > --- a/gdb/compile/compile-object-run.c > +++ b/gdb/compile/compile-object-run.c > @@ -32,6 +32,17 @@ > > struct do_module_cleanup > { > + do_module_cleanup () = default; > + > + ~do_module_cleanup () > + { > + delete munmap_list_head; > + xfree (source_file); > + xfree (objfile_name_string); > + } > + > + DISABLE_COPY_AND_ASSIGN (do_module_cleanup); > + Seeing this makes me a bit nervous, as it easily allows the destructor run on an object whose fields have not been initialized. So it will call delete/xfree on uninitialized pointers. So I'd rather introduce a constructor before introducing a destructor, or simultaneously. The next patches touch that code, so I presume that will change. But I read patches in a very linear way, so that is my comment at this intermediary point :). Simon