From: Ian Rogers <irogers@google.com>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Jiri Olsa <jolsa@redhat.com>, Ingo Molnar <mingo@kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Stephane Eranian <eranian@google.com>,
LKML <linux-kernel@vger.kernel.org>,
Andi Kleen <andi@firstfloor.org>,
Kajol Jain <kjain@linux.ibm.com>,
John Garry <john.garry@huawei.com>
Subject: Re: [PATCH] perf metric: Fix some memory leaks
Date: Thu, 3 Sep 2020 21:02:38 -0700 [thread overview]
Message-ID: <CAP-5=fXjeCBemNivMb6+9AH-PETTqTghaZHniOohd_1ms1rU2A@mail.gmail.com> (raw)
In-Reply-To: <20200904032142.516333-1-namhyung@kernel.org>
On Thu, Sep 3, 2020 at 8:21 PM Namhyung Kim <namhyung@kernel.org> wrote:
>
> I found some memory leaks while reading the metric code. Some are
> real and others only occur in the error path.
Thanks Namhyung! Is it possible to get test coverage?
Ian
> Cc: Kajol Jain <kjain@linux.ibm.com>
> Cc: John Garry <john.garry@huawei.com>
> Cc: Ian Rogers <irogers@google.com>
> Fixes: 9afe5658a6fa8 ("perf tools: Release metric_events rblist")
> Fixes: 4ea2896715e67 ("perf metric: Collect referenced metrics in struct metric_expr")
> Fixes: 71b0acce78d12 ("perf list: Add metric groups to perf list")
> Fixes: b18f3e365019d ("perf stat: Support JSON metrics in perf stat")
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>
> ---
> I'm not sure it'd better have them together or split each fix as
> they came from different commits. Please let me know if you prefer
> split.
>
> tools/perf/util/metricgroup.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
> index 8831b964288f..7e31c4578ce8 100644
> --- a/tools/perf/util/metricgroup.c
> +++ b/tools/perf/util/metricgroup.c
> @@ -85,6 +85,7 @@ static void metric_event_delete(struct rblist *rblist __maybe_unused,
>
> list_for_each_entry_safe(expr, tmp, &me->head, nd) {
> free(expr->metric_refs);
> + free(expr->metric_events);
> free(expr);
> }
>
> @@ -316,6 +317,7 @@ static int metricgroup__setup_events(struct list_head *groups,
> if (!metric_refs) {
> ret = -ENOMEM;
> free(metric_events);
> + free(expr);
> break;
> }
>
> @@ -530,6 +532,9 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter,
> continue;
> strlist__add(me->metrics, s);
> }
> +
> + if (!raw)
> + free(s);
> }
> free(omg);
> }
> @@ -1048,11 +1053,11 @@ static int parse_groups(struct evlist *perf_evlist, const char *str,
> parse_events_print_error(&parse_error, extra_events.buf);
> goto out;
> }
> - strbuf_release(&extra_events);
> ret = metricgroup__setup_events(&metric_list, metric_no_merge,
> perf_evlist, metric_events);
> out:
> metricgroup__free_metrics(&metric_list);
> + strbuf_release(&extra_events);
> return ret;
> }
>
> --
> 2.28.0.526.ge36021eeef-goog
>
next prev parent reply other threads:[~2020-09-04 4:02 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-04 3:21 [PATCH] perf metric: Fix some memory leaks Namhyung Kim
2020-09-04 4:02 ` Ian Rogers [this message]
2020-09-04 13:39 ` Namhyung Kim
2020-09-04 16:28 ` Arnaldo Carvalho de Melo
2020-09-05 1:58 ` Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAP-5=fXjeCBemNivMb6+9AH-PETTqTghaZHniOohd_1ms1rU2A@mail.gmail.com' \
--to=irogers@google.com \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=andi@firstfloor.org \
--cc=eranian@google.com \
--cc=john.garry@huawei.com \
--cc=jolsa@redhat.com \
--cc=kjain@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).