From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by sourceware.org (Postfix) with ESMTP id F4186385803F for ; Mon, 5 Apr 2021 16:23:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F4186385803F Received: from vapier (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 8BDEF335D67; Mon, 5 Apr 2021 16:23:55 +0000 (UTC) Date: Mon, 5 Apr 2021 12:23:55 -0400 From: Mike Frysinger To: Simon Marchi Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] sim/m32c: fix memory leaks in opc2c Message-ID: Mail-Followup-To: Simon Marchi , gdb-patches@sourceware.org References: <20210405145856.3925296-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210405145856.3925296-1-simon.marchi@polymtl.ca> X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, 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: Mon, 05 Apr 2021 16:23:59 -0000 On 05 Apr 2021 10:58, Simon Marchi via Gdb-patches wrote: > Fix the leak in dump_lines by free-ing the elements of varnames. i dislike stuffing a bunch of free's at the end of a program's lifetime just to satisfy a tool that is not normally used. which isn't to say LSAN isn't useful, just that i think we should do better. in other codebases, i've done things like: #ifdef __SANITIZE_ADDRESS__ # define ENABLE_CLEANUP_ONEXIT 1 #else # define ENABLE_CLEANUP_ONEXIT 0 #endif then this could be written: if (ENABLE_CLEANUP_ONEXIT) { for (i = 0; i < vn; i++) free (varnames[i]); } wdyt ? feel free to bikeshed the name. not sure if there's prior art in the tree currently. -mike