Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp691654pxv; Thu, 15 Jul 2021 13:35:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnZki2rmLmMbvSriU06UXNLC7LQOAcKHk84JoIqG7Pe1fV+IzOsDa599SBiCN5a7OCj1sv X-Received: by 2002:a17:906:cb86:: with SMTP id mf6mr7698571ejb.116.1626381355425; Thu, 15 Jul 2021 13:35:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626381355; cv=none; d=google.com; s=arc-20160816; b=1FSsT3EfGm0w8Zx5Z7/AczU+bJSiyDK974xK9opfb9geQwO51+AQn+QG60XZnCzbVQ yLtTfG5ZPW3OW7rgEreU3XMSxyE3m+bfJ6Vhqfahig1gydxGkjoEVd4tV/n5Pa+9My1p u7q6MGNib8YVy8rLPY9hUbBrDKyO+WlgK9RjLBvGJPqikyGmP9nB2g9xpPTLPc3QW1lc +Ay/MP+CigLVwggvnNSlgpviLfTlHYR4HeQDtwDh4mA5ipP8+eaZ6kB0vcynkEG2S8E3 EtzL8HsbvTBf51RPHltexRgmeJ5Itostzf702+geVVegWKatYfGGUOYxB3GEGnze1Kbn oE3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=S2j5mYTBr+BiCUp5+H4DxJcTPMqn2sx6oHvdZBPYqZ8=; b=NKlKdiVDh0L2Otgq+9sSA21mamPZaysHupcI5vXdFXHsb2QqRPbiBFG9kokNz9Wt3Q KHKDK53vEeStA4yW7TAqvzzzaZZQRBU9SXsei8xux7gboKTUOV1IFwbIJ5anO+ov5Npp HojB5loPuCl582IKjwoJ3axNrVdy5nSz7VwXVTGwpIzCSf6cvcd1QolFtpdJFyeJfvc9 v0Z8PZ6aw3ZxmvB5YViddDxc8YjvL++Ft+0zSKq1fIqXUTynAs4DMMobgwXxhGj+Pz7M RaT63XYUQ945dEPSfdbLNF+/mTSL0s7ht00mxT3BDkxz3ApxrpT5cz7EBmjnhT9gRDqG Lmqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ev1Pg9JI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id df12si8713739edb.406.2021.07.15.13.35.32; Thu, 15 Jul 2021 13:35:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Ev1Pg9JI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235808AbhGOUfU (ORCPT + 99 others); Thu, 15 Jul 2021 16:35:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:59130 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231397AbhGOUfU (ORCPT ); Thu, 15 Jul 2021 16:35:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E013B613D2; Thu, 15 Jul 2021 20:32:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626381146; bh=Zpn1XMUEVhwEW6EqfhkrxX8vH43xiXgmKI68iCHQDf0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Ev1Pg9JIRzTFZWqP+oNkruYsW1FsqyMlDmWubZB8k0HIJeo8Dx8xmErHCTUVOmlBb 2a6eGHy7bFT+5DG24UzZ1484wGTaQGH4k/9ZEXN/paWQeq3t++YyUptAXSaPdt1vWk pvDDh1NuY/JG+7dF97pgAJsxS1KNrl62gseHojBpoAJ/bbc014oBZvMW64CPeUcLVz LludzO6yUOfws5ByKL4R6XBnopV7uDotZwqhglIt/honV+SadL01H+gpAq30G3vjUO E/2YJ8yBgRxgpJepPk8iaaThBX23xAYiUqr68RDoEMEEHaYbpSvkW+0r+rRuK0Y4KE Vt6TxNl2Pt6fQ== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 99D16403F2; Thu, 15 Jul 2021 17:32:23 -0300 (-03) Date: Thu, 15 Jul 2021 17:32:23 -0300 From: Arnaldo Carvalho de Melo To: Riccardo Mancini Cc: Ian Rogers , Namhyung Kim , Peter Zijlstra , Ingo Molnar , Mark Rutland , Jiri Olsa , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: Re: [PATCH 15/20] perf trace: free malloc'd trace fields on exit Message-ID: References: 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 Thu, Jul 15, 2021 at 06:07:20PM +0200, Riccardo Mancini escreveu: > ASan reports several memory leaks running the perf test > "88: Check open filename arg using perf trace + vfs_getname". > The first of these leaks is related to struct trace fields never being > deallocated. > > This patch adds the function trace__exit, which is called at the end of > cmd_trace, replacing the existing deallocation, which is now moved > inside the new function. > This function deallocates: > - ev_qualifier > - ev_qualifier_ids.entries > - syscalls.table > - sctbl > - perfconfig_events > > In order to prevent errors in case any of this field is never > initialized, this patch also adds initialization to NULL to these > fields. > > Signed-off-by: Riccardo Mancini > --- > tools/perf/builtin-trace.c | 17 ++++++++++++++++- > 1 file changed, 16 insertions(+), 1 deletion(-) > > diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c > index 7ec18ff57fc4ae35..fe26d87ca8ccc14d 100644 > --- a/tools/perf/builtin-trace.c > +++ b/tools/perf/builtin-trace.c > @@ -4701,6 +4701,15 @@ static int trace__config(const char *var, const char *value, void *arg) > return err; > } > > +static void trace__exit(struct trace *trace) > +{ > + strlist__delete(trace->ev_qualifier); > + free(trace->ev_qualifier_ids.entries); > + free(trace->syscalls.table); > + syscalltbl__delete(trace->sctbl); > + zfree(&trace->perfconfig_events); > +} > + > int cmd_trace(int argc, const char **argv) > { > const char *trace_usage[] = { > @@ -4731,6 +4740,12 @@ int cmd_trace(int argc, const char **argv) > .kernel_syscallchains = false, > .max_stack = UINT_MAX, > .max_events = ULONG_MAX, > + .ev_qualifier = NULL, > + .sctbl = NULL, > + .ev_qualifier_ids = { > + .entries = NULL, > + .nr = 0, > + }, > }; > const char *map_dump_str = NULL; > const char *output_name = NULL; The above hunk is not needed, as all non explicitely initialized members will be zeroed, so to reduce patch size I'm dropping it. Thanks, applied. - Arnaldo > @@ -5135,6 +5150,6 @@ int cmd_trace(int argc, const char **argv) > if (output_name != NULL) > fclose(trace.output); > out: > - zfree(&trace.perfconfig_events); > + trace__exit(&trace); > return err; > } > -- > 2.31.1 > -- - Arnaldo