* [PATCH] perf metric: Fix some memory leaks
@ 2020-09-04 3:21 Namhyung Kim
2020-09-04 4:02 ` Ian Rogers
0 siblings, 1 reply; 5+ messages in thread
From: Namhyung Kim @ 2020-09-04 3:21 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Jiri Olsa
Cc: Ingo Molnar, Peter Zijlstra, Mark Rutland, Alexander Shishkin,
Stephane Eranian, LKML, Andi Kleen, Kajol Jain, John Garry,
Ian Rogers
I found some memory leaks while reading the metric code. Some are
real and others only occur in the error path.
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] perf metric: Fix some memory leaks
2020-09-04 3:21 [PATCH] perf metric: Fix some memory leaks Namhyung Kim
@ 2020-09-04 4:02 ` Ian Rogers
2020-09-04 13:39 ` Namhyung Kim
0 siblings, 1 reply; 5+ messages in thread
From: Ian Rogers @ 2020-09-04 4:02 UTC (permalink / raw)
To: Namhyung Kim
Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar, Peter Zijlstra,
Mark Rutland, Alexander Shishkin, Stephane Eranian, LKML,
Andi Kleen, Kajol Jain, John Garry
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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] perf metric: Fix some memory leaks
2020-09-04 4:02 ` Ian Rogers
@ 2020-09-04 13:39 ` Namhyung Kim
2020-09-04 16:28 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 5+ messages in thread
From: Namhyung Kim @ 2020-09-04 13:39 UTC (permalink / raw)
To: Ian Rogers
Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar, Peter Zijlstra,
Mark Rutland, Alexander Shishkin, Stephane Eranian, LKML,
Andi Kleen, Kajol Jain, John Garry
On Fri, Sep 4, 2020 at 1:02 PM Ian Rogers <irogers@google.com> wrote:
>
> 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
Not sure what you want..
As I found it from code inspection I don't know if there's a test covering this.
But as far as I can see, 2 of them are on the error path so maybe not easy
to add a test, other one is called from perf list code, and the last one is on
the normal code path so any test should cover it.
Thanks
Namhyung
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] perf metric: Fix some memory leaks
2020-09-04 13:39 ` Namhyung Kim
@ 2020-09-04 16:28 ` Arnaldo Carvalho de Melo
2020-09-05 1:58 ` Namhyung Kim
0 siblings, 1 reply; 5+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-09-04 16:28 UTC (permalink / raw)
To: Namhyung Kim
Cc: Ian Rogers, Jiri Olsa, Ingo Molnar, Peter Zijlstra, Mark Rutland,
Alexander Shishkin, Stephane Eranian, LKML, Andi Kleen,
Kajol Jain, John Garry
Em Fri, Sep 04, 2020 at 10:39:50PM +0900, Namhyung Kim escreveu:
> On Fri, Sep 4, 2020 at 1:02 PM Ian Rogers <irogers@google.com> wrote:
> >
> > 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
>
> Not sure what you want..
>
> As I found it from code inspection I don't know if there's a test covering this.
>
> But as far as I can see, 2 of them are on the error path so maybe not easy
> to add a test, other one is called from perf list code, and the last one is on
> the normal code path so any test should cover it.
Humm, I assume all those fixes were for csets in a single Linux version,
right? Otherwise I think it'd be better to have a fix per Fixes tag, so
that they would go to the kernel sources where those bugs were fixed.
Thanks!
- Arnaldo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] perf metric: Fix some memory leaks
2020-09-04 16:28 ` Arnaldo Carvalho de Melo
@ 2020-09-05 1:58 ` Namhyung Kim
0 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2020-09-05 1:58 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo
Cc: Ian Rogers, Jiri Olsa, Ingo Molnar, Peter Zijlstra, Mark Rutland,
Alexander Shishkin, Stephane Eranian, LKML, Andi Kleen,
Kajol Jain, John Garry
Hi Arnaldo,
On Sat, Sep 5, 2020 at 1:28 AM Arnaldo Carvalho de Melo <acme@kernel.org> wrote:
> Humm, I assume all those fixes were for csets in a single Linux version,
> right? Otherwise I think it'd be better to have a fix per Fixes tag, so
> that they would go to the kernel sources where those bugs were fixed.
$ git name-rev --tags 9afe5658a6fa8 4ea2896715e67 71b0acce78d12 b18f3e365019d
9afe5658a6fa8 tags/v5.9-rc1~66^2~135
4ea2896715e67 tags/v5.9-rc1~66^2~55
71b0acce78d12 tags/v4.15-rc1~160^2~38^2~36
b18f3e365019d tags/v4.15-rc1~160^2~38^2~37
I'll split it to two - one for v4.15 and another for v5.9.
Thanks
Namhyung
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-09-05 1:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-04 3:21 [PATCH] perf metric: Fix some memory leaks Namhyung Kim
2020-09-04 4:02 ` Ian Rogers
2020-09-04 13:39 ` Namhyung Kim
2020-09-04 16:28 ` Arnaldo Carvalho de Melo
2020-09-05 1:58 ` Namhyung Kim
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).