From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from aserp2120.oracle.com (aserp2120.oracle.com [141.146.126.78]) by sourceware.org (Postfix) with ESMTPS id B334B385781C for ; Thu, 1 Apr 2021 19:00:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B334B385781C Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 131IroIP100086; Thu, 1 Apr 2021 19:00:06 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by aserp2120.oracle.com with ESMTP id 37n2akjx1s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 01 Apr 2021 19:00:06 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 131Itcdi122690; Thu, 1 Apr 2021 19:00:05 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 37n2at71hu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 01 Apr 2021 19:00:04 +0000 Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 131J039C029652; Thu, 1 Apr 2021 19:00:03 GMT Received: from [10.159.255.43] (/10.159.255.43) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 01 Apr 2021 12:00:03 -0700 Subject: Re: [PATCH,V3 1/3] CTF: fix incorrect function return type To: Tom Tromey , Weimin Pan via Gdb-patches References: <1617237594-24175-1-git-send-email-weimin.pan@oracle.com> <1617237594-24175-2-git-send-email-weimin.pan@oracle.com> <87a6qiq72v.fsf@tromey.com> From: Wei-min Pan Message-ID: <5fbf5094-46eb-51b3-241b-69564dd653cb@oracle.com> Date: Thu, 1 Apr 2021 12:00:01 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <87a6qiq72v.fsf@tromey.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9941 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 phishscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 bulkscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103310000 definitions=main-2104010122 X-Proofpoint-ORIG-GUID: ir3iVrho3nI6NN1BxL16Dhe0Z4HyicU_ X-Proofpoint-GUID: ir3iVrho3nI6NN1BxL16Dhe0Z4HyicU_ X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=9941 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 impostorscore=0 phishscore=0 bulkscore=0 adultscore=0 clxscore=1011 malwarescore=0 priorityscore=1501 suspectscore=0 spamscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2103310000 definitions=main-2104010122 X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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: Thu, 01 Apr 2021 19:00:10 -0000 On 4/1/2021 9:54 AM, Tom Tromey wrote: >>>>>> Weimin Pan via Gdb-patches writes: >> + Don't copy name returned from ctf_type_aname_raw throughout file. > To be clear, this relies on the pointers from libctf having the correct > lifetime. If that's not the case, you'll get crashes. > >> - gdb::unique_xmalloc_ptr name (ctf_type_aname_raw (fp, tid)); >> + char *name = ctf_type_aname_raw (fp, tid); > Dropping the unique_xmalloc_ptr here makes me suspect that > ctf_type_aname_raw is returning a malloc'd pointer. So, this change > would seem to leak memory. Function ctf_type_aname_raw does strdup the type name. So it won't crash but will cause mamory leaks as you suspected. Instead should have used the combination of another libctf function ctf_type_name_raw which doesn't strdup the name and unique_xmalloc_ptr. Thank you very much for the comment. > > Tom