From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 60729 invoked by alias); 3 Oct 2019 18:53:14 -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 60721 invoked by uid 89); 3 Oct 2019 18:53:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-6.8 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: userp2130.oracle.com Received: from userp2130.oracle.com (HELO userp2130.oracle.com) (156.151.31.86) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 03 Oct 2019 18:53:12 +0000 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x93In9LD136160; Thu, 3 Oct 2019 18:53:10 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2019-08-05; bh=wtRu2XGifkfqcos3XVFaaWgC01geDTCgLkS3vCacre4=; b=KTge8jHyCl1xWbbPhBXrRvaPwepN1aKmKDmiMyItiU5qk7RK+aHs+nk3cMjaMYTz6MbR plCb1cJYs990GXRZV6GfuAu0RMl2YJYbPLmxdKieMcLOGtAnUFo9be7mmkTO6D5Apzw/ bEaMuft1WHyfkvYfTlX+M7+N4jjh+wwOAAHEAznjxBos1Sh+D4kDCaJgRtC/+6l0ZE1K dvG7cRxyR+gdt0KbN4Xz6VJR2LfHFLJ1G3cojKD8WsEesRFTstkmnVxFUC2edm6JDGhO gmZjdYvjsksrhznBBQhyJLeMyqxHo6OhiYXkGzWkJIPTcFjOfuLg+qD8v5W35DhaSfUH YA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 2v9xxv6dhg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 03 Oct 2019 18:53:09 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x93Im72j107116; Thu, 3 Oct 2019 18:53:09 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 2vckyr8w11-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 03 Oct 2019 18:53:08 +0000 Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x93Ir7Zv030044; Thu, 3 Oct 2019 18:53:07 GMT Received: from [10.159.232.91] (/10.159.232.91) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 03 Oct 2019 11:53:07 -0700 Subject: Re: [PATCH v2] gdb: CTF support To: Simon Marchi , gdb-patches@sourceware.org References: <1564530195-27659-1-git-send-email-weimin.pan@oracle.com> <5377c457-52b0-583d-15b5-47024eae1f48@simark.ca> <895f47d4-3e01-4d5a-474b-43dd2dd037b4@oracle.com> <0fe82814-46b8-79c2-6a25-5f5d51b158e1@simark.ca> <1055d18f-9e5c-3344-114a-3777876c9c63@oracle.com> <3a67839f-73d0-06ed-4140-073306fc618d@simark.ca> <75851ff5-771d-16fb-0a74-661c9e0722d3@simark.ca> <93caabd4-f25d-61e3-a11d-52bcd8fbe3b6@simark.ca> From: Wei-min Pan Message-ID: <9f1e47a9-f558-5d7e-1086-7708ac394d7f@oracle.com> Date: Thu, 03 Oct 2019 18:53:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <93caabd4-f25d-61e3-a11d-52bcd8fbe3b6@simark.ca> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-SW-Source: 2019-10/txt/msg00126.txt.bz2 On 10/3/2019 11:31 AM, Simon Marchi wrote: > On 2019-10-03 2:21 p.m., Wei-min Pan wrote: >> Let's use an example (checking omitted): >> >> We're replacing: >>   name = ctf_type_aname_raw (fp, tid); >>   TYPE_NAME (type) = obstack_strdup (&of->objfile_obstack, name); >>   free (name); >> >> with >>   gdb::unique_xmalloc_ptr name (ctf_type_aname_raw (fp, tid)); >>   TYPE_NAME (type) = obstack_strdup (&of->objfile_obstack, name.get ()); >> >> The allocated copy from ctf_type_aname_raw is not freed. Or did I miss something? >> >> Weimin > Yes, the second snippet frees the copy returned by ctf_type_aname_raw. > > It might just be that you are not familiar with the concept of std::unique_ptr in C++: > > https://en.cppreference.com/w/cpp/memory/unique_ptr > > It's a wrapper around a simple pointer that automatically calls a deleter function > when it goes out of scope. gdb::unique_xmalloc_ptr is a specialization of std::unique_ptr > that uses xfree as the deleter function. > > Here's a similar use: > > https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=gdb/fbsd-tdep.c;h=9422e3c1a7e1a65c76b088f42bb5986bd13a089f;hb=HEAD#l1530 > > `fbsd_core_vnode_path` return a pointer to an allocated C String, which `cwd` wraps. When > it goes out of scope, `cwd` automatically calls `xfree` with the pointer. Oh, thanks for the explanation, reference and example. Will switch to using gdb::unique_xmalloc_ptr<> instead. Weimin > > Simon