2020-05-21 13:35:15

by liwei (GF)

[permalink] [raw]
Subject: [PATCH 1/4] perf metrictroup: Fix memory leak of metric_events

From: Hongbo Yao <[email protected]>

Fix memory leak of metric_events in function metricgroup__setup_events()

Signed-off-by: Hongbo Yao <[email protected]>
---
tools/perf/util/metricgroup.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 926449a7cdbf..69bf0f4d646e 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -184,6 +184,7 @@ static int metricgroup__setup_events(struct list_head *groups,
if (!evsel) {
pr_debug("Cannot resolve %s: %s\n",
eg->metric_name, eg->metric_expr);
+ free(metric_events);
continue;
}
for (i = 0; i < eg->idnum; i++)
@@ -191,11 +192,13 @@ static int metricgroup__setup_events(struct list_head *groups,
me = metricgroup__lookup(metric_events_list, evsel, true);
if (!me) {
ret = -ENOMEM;
+ free(metric_events);
break;
}
expr = malloc(sizeof(struct metric_expr));
if (!expr) {
ret = -ENOMEM;
+ free(metric_events);
break;
}
expr->metric_expr = eg->metric_expr;
--
2.17.1


2020-05-21 15:57:57

by Arnaldo Carvalho de Melo

[permalink] [raw]
Subject: Re: [PATCH 1/4] perf metrictroup: Fix memory leak of metric_events

Em Thu, May 21, 2020 at 09:32:15PM +0800, Wei Li escreveu:
> From: Hongbo Yao <[email protected]>
>
> Fix memory leak of metric_events in function metricgroup__setup_events()

The leak is there but this code has changed a lot recently, please take
a look at my perf/core branch and keep Ian Rogers in the loop,

- Arnaldo

> Signed-off-by: Hongbo Yao <[email protected]>
> ---
> tools/perf/util/metricgroup.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
> index 926449a7cdbf..69bf0f4d646e 100644
> --- a/tools/perf/util/metricgroup.c
> +++ b/tools/perf/util/metricgroup.c
> @@ -184,6 +184,7 @@ static int metricgroup__setup_events(struct list_head *groups,
> if (!evsel) {
> pr_debug("Cannot resolve %s: %s\n",
> eg->metric_name, eg->metric_expr);
> + free(metric_events);
> continue;
> }
> for (i = 0; i < eg->idnum; i++)
> @@ -191,11 +192,13 @@ static int metricgroup__setup_events(struct list_head *groups,
> me = metricgroup__lookup(metric_events_list, evsel, true);
> if (!me) {
> ret = -ENOMEM;
> + free(metric_events);
> break;
> }
> expr = malloc(sizeof(struct metric_expr));
> if (!expr) {
> ret = -ENOMEM;
> + free(metric_events);
> break;
> }
> expr->metric_expr = eg->metric_expr;
> --
> 2.17.1
>

--

- Arnaldo

2020-05-21 16:13:22

by Ian Rogers

[permalink] [raw]
Subject: Re: [PATCH 1/4] perf metrictroup: Fix memory leak of metric_events

On Thu, May 21, 2020 at 8:54 AM Arnaldo Carvalho de Melo
<[email protected]> wrote:
>
> Em Thu, May 21, 2020 at 09:32:15PM +0800, Wei Li escreveu:
> > From: Hongbo Yao <[email protected]>
> >
> > Fix memory leak of metric_events in function metricgroup__setup_events()
>
> The leak is there but this code has changed a lot recently, please take
> a look at my perf/core branch and keep Ian Rogers in the loop,
>
> - Arnaldo

Thanks, I'd posted the same change here:
https://lore.kernel.org/lkml/[email protected]/
but it looks like it was mislaid. Arnaldo, I can re-post that patch or
Acked-by this patch. I'm easy either way.

Thanks,
Ian

> > Signed-off-by: Hongbo Yao <[email protected]>
> > ---
> > tools/perf/util/metricgroup.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
> > index 926449a7cdbf..69bf0f4d646e 100644
> > --- a/tools/perf/util/metricgroup.c
> > +++ b/tools/perf/util/metricgroup.c
> > @@ -184,6 +184,7 @@ static int metricgroup__setup_events(struct list_head *groups,
> > if (!evsel) {
> > pr_debug("Cannot resolve %s: %s\n",
> > eg->metric_name, eg->metric_expr);
> > + free(metric_events);
> > continue;
> > }
> > for (i = 0; i < eg->idnum; i++)
> > @@ -191,11 +192,13 @@ static int metricgroup__setup_events(struct list_head *groups,
> > me = metricgroup__lookup(metric_events_list, evsel, true);
> > if (!me) {
> > ret = -ENOMEM;
> > + free(metric_events);
> > break;
> > }
> > expr = malloc(sizeof(struct metric_expr));
> > if (!expr) {
> > ret = -ENOMEM;
> > + free(metric_events);
> > break;
> > }
> > expr->metric_expr = eg->metric_expr;
> > --
> > 2.17.1
> >
>
> --
>
> - Arnaldo