From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 82313 invoked by alias); 5 Jan 2018 02:58:28 -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 82304 invoked by uid 89); 5 Jan 2018 02:58:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: simark.ca Received: from simark.ca (HELO simark.ca) (158.69.221.121) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 05 Jan 2018 02:58:26 +0000 Received: from [10.0.0.11] (192-222-251-162.qc.cable.ebox.net [192.222.251.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 191A41E02D; Thu, 4 Jan 2018 21:58:24 -0500 (EST) Subject: Re: [PATCH v2 3/5] Use gdb::unique_xmalloc_ptr<> instead of a deleter that invokes free(). To: John Baldwin , gdb-patches@sourceware.org References: <20180104014923.11899-1-jhb@FreeBSD.org> <20180104014923.11899-4-jhb@FreeBSD.org> From: Simon Marchi Message-ID: <1c44f13c-cdae-0578-e49d-1d13ed6530a9@simark.ca> Date: Fri, 05 Jan 2018 02:58:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <20180104014923.11899-4-jhb@FreeBSD.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2018-01/txt/msg00064.txt.bz2 On 2018-01-03 08:49 PM, John Baldwin wrote: > Since xfree() always wraps free(), it is safe to use the xfree deleter > for buffers allocated by library routines such as kinfo_getvmmap() that > must be released via free(). > > gdb/ChangeLog: > > * fbsd-nat.c (struct free_deleter): Remove. > (fbsd_find_memory_regions): Use gdb::unique_xmalloc_ptr<>. > --- > gdb/ChangeLog | 5 +++++ > gdb/fbsd-nat.c | 10 +--------- > 2 files changed, 6 insertions(+), 9 deletions(-) > > diff --git a/gdb/ChangeLog b/gdb/ChangeLog > index 804dd4f402..cdce396e9c 100644 > --- a/gdb/ChangeLog > +++ b/gdb/ChangeLog > @@ -1,3 +1,8 @@ > +2018-01-03 John Baldwin > + > + * fbsd-nat.c (struct free_deleter): Remove. > + (fbsd_find_memory_regions): Use gdb::unique_xmalloc_ptr<>. > + > 2018-01-03 John Baldwin > > * fbsd-nat.c (fbsd_pid_to_exec_file) [KERN_PROC_PATHNAME]: Return > diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c > index 7b1d1bf148..00e5cfb55c 100644 > --- a/gdb/fbsd-nat.c > +++ b/gdb/fbsd-nat.c > @@ -78,14 +78,6 @@ fbsd_pid_to_exec_file (struct target_ops *self, int pid) > } > > #ifdef HAVE_KINFO_GETVMMAP > -/* Deleter for std::unique_ptr that invokes free. */ > - > -template > -struct free_deleter > -{ > - void operator() (T *ptr) const { free (ptr); } > -}; > - > /* Iterate over all the memory regions in the current inferior, > calling FUNC for each memory region. OBFD is passed as the last > argument to FUNC. */ > @@ -99,7 +91,7 @@ fbsd_find_memory_regions (struct target_ops *self, > uint64_t size; > int i, nitems; > > - std::unique_ptr> > + gdb::unique_xmalloc_ptr > vmentl (kinfo_getvmmap (pid, &nitems)); > if (vmentl == NULL) > perror_with_name (_("Couldn't fetch VM map entries.")); > LGTM, unless there's something I really havn't understood about xfree. Simon