From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 256643858D37 for ; Tue, 30 Jun 2020 22:26:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 256643858D37 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 05UMQqre009615 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 30 Jun 2020 18:26:57 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 05UMQqre009615 Received: from [172.16.0.95] (192-222-181-218.qc.cable.ebox.net [192.222.181.218]) (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 D49041E797; Tue, 30 Jun 2020 18:26:52 -0400 (EDT) Subject: Re: [PATCH 2/3] gdb: make macro_expand_next return a gdb::unique_xmalloc_ptr To: Tom Tromey , Simon Marchi via Gdb-patches References: <20200628165628.96730-1-simon.marchi@polymtl.ca> <20200628165628.96730-3-simon.marchi@polymtl.ca> <87v9j88edi.fsf@tromey.com> From: Simon Marchi Message-ID: Date: Tue, 30 Jun 2020 18:26:52 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <87v9j88edi.fsf@tromey.com> Content-Type: text/plain; charset=utf-8 Content-Language: tl Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Tue, 30 Jun 2020 22:26:53 +0000 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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: Tue, 30 Jun 2020 22:27:00 -0000 On 2020-06-30 4:53 p.m., Tom Tromey wrote: >>>>>> "Simon" == Simon Marchi via Gdb-patches writes: > > Simon> I removed the ATTRIBUTE_UNUSED_RESULT on macro_buffer::release, I don't > Simon> really understand why it's there. I don't see how this method could be > Simon> called without using the result, that would be an obvious memory leak. > Simon> The commit that introduced it (4e4a8b932b7 "Add ATTRIBUTE_UNUSED_RESULT > Simon> to macro_buffer") doesn't give any details. > > Sorry about the lack of details! > > Simon> - /* Release the text of the buffer to the caller, which is now > Simon> - responsible for freeing it. */ > Simon> - ATTRIBUTE_UNUSED_RESULT char *release () > Simon> + /* Release the text of the buffer to the caller. */ > Simon> + gdb::unique_xmalloc_ptr release () > > In the old code, the caller had to remember to free the resulting char*. > ATTRIBUTE_UNUSED_RESULT meant that one couldn't write "x.release();" > without at least doing something with the result. > > There was at least one case of this happening, though I didn't read > through the thread to find out exactly where it was: > > https://sourceware.org/pipermail/gdb-patches/2019-February/155835.html > > Using a unique pointer eliminates this common source of bugs, so I think > removing the attribute makes sense. > > This patch looks fine to me. > > Tom > Ok thanks, that makes sense! Simon