From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EA2B2DF84 for ; Mon, 27 Nov 2023 13:18:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Pl2TTh2k" 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> Precedence: bulk X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com 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