From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 837DEC4167B for ; Mon, 27 Nov 2023 13:18:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233476AbjK0NSB (ORCPT ); Mon, 27 Nov 2023 08:18:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233358AbjK0NR7 (ORCPT ); Mon, 27 Nov 2023 08:17:59 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4CDC10F for ; Mon, 27 Nov 2023 05:18:05 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64A01C433C7; Mon, 27 Nov 2023 13:18:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701091085; bh=McrNEpfZZaZARie6QYahkn6MCqkCCeXaKU1VOHtga9E=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Pl2TTh2kcriaU1EUjLRa4gu4jUprUbnia5vCe+KAgNDrKYJX8dgFzPsUswbNMNL/I 8AzdlrFXpL0pmzcWbUg/qcZ+jxFrX0j2mt/N2pK1sK/H9ai0OwbCMitdmd78IOBau8 WEIlCVyKm/SshMKPi1akWI8CKHsAHvGD3s0JhCGOLXcKG3JfuaPwTfPsD7fGPJ+J6L LJNqcBVbuzfjcBWWEnG7HXcSSDr1X7n8P0NJysuBIGkCoppp8OK4G2HgrbVokqEQNT yZMqHSCrSs6eRn0BvSuiGmB8qSnAecgrJdOuZ9/ZbDCR0UlsjY1S4O2yZi2ivp4Wr7 d2I18wWFr/h7Q== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 1920B40094; Mon, 27 Nov 2023 10:18:03 -0300 (-03) Date: Mon, 27 Nov 2023 10:18:03 -0300 From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Peter Zijlstra , zhaimingbing , Namhyung Kim , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Sean Christopherson , Li Dong , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf lock: Fix a memory leak on an error path Message-ID: References: <20231124092657.10392-1-zhaimingbing@cmss.chinamobile.com> <20231124095319.GN3818@noisy.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, Nov 24, 2023 at 01:56:35PM +0100, Ingo Molnar escreveu: > > * Peter Zijlstra wrote: > > > On Fri, Nov 24, 2023 at 05:26:57PM +0800, zhaimingbing wrote: > > > if a strdup-ed string is NULL,the allocated memory needs freeing. > > > > > > Signed-off-by: zhaimingbing > > > --- > > > tools/perf/builtin-lock.c | 4 +++- > > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > > > diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c > > > index b141f2134..086041bcb 100644 > > > --- a/tools/perf/builtin-lock.c > > > +++ b/tools/perf/builtin-lock.c > > > @@ -2228,8 +2228,10 @@ static int __cmd_record(int argc, const char **argv) > > > else > > > ev_name = strdup(contention_tracepoints[j].name); > > > > > > - if (!ev_name) > > > + if (!ev_name) { > > > + free(rec_argv); > > > return -ENOMEM; > > > + } > > > > Isn't this an error path straight into exit? > > It increases the quality of implementation if resources are free()d > consistently regardless of whether the task is going to exit() immediately, > for example it makes it easier to validate perf for the lack of memory > leaks with Valgrind. I'm taking this positive comment about the patch as an Acked-by, ok? - Arnaldo