There is a memory leak problem in the failure paths of
build_cl_output(), so fix it.
Signed-off-by: Yunfeng Ye <[email protected]>
---
tools/perf/builtin-c2c.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 3542b6a..e69f449 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -2635,6 +2635,7 @@ static int build_cl_output(char *cl_sort, bool no_source)
bool add_sym = false;
bool add_dso = false;
bool add_src = false;
+ int ret = 0;
if (!buf)
return -ENOMEM;
@@ -2653,7 +2654,8 @@ static int build_cl_output(char *cl_sort, bool no_source)
add_dso = true;
} else if (strcmp(tok, "offset")) {
pr_err("unrecognized sort token: %s\n", tok);
- return -EINVAL;
+ ret = -EINVAL;
+ goto err;
}
}
@@ -2676,13 +2678,15 @@ static int build_cl_output(char *cl_sort, bool no_source)
add_sym ? "symbol," : "",
add_dso ? "dso," : "",
add_src ? "cl_srcline," : "",
- "node") < 0)
- return -ENOMEM;
+ "node") < 0) {
+ ret = -ENOMEM;
+ goto err;
+ }
c2c.show_src = add_src;
-
+err:
free(buf);
- return 0;
+ return ret;
}
static int setup_coalesce(const char *coalesce, bool no_source)
--
2.7.4.3
On Tue, Oct 15, 2019 at 10:54:14AM +0800, Yunfeng Ye wrote:
> There is a memory leak problem in the failure paths of
> build_cl_output(), so fix it.
>
> Signed-off-by: Yunfeng Ye <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
thanks,
jirka
> ---
> tools/perf/builtin-c2c.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
> index 3542b6a..e69f449 100644
> --- a/tools/perf/builtin-c2c.c
> +++ b/tools/perf/builtin-c2c.c
> @@ -2635,6 +2635,7 @@ static int build_cl_output(char *cl_sort, bool no_source)
> bool add_sym = false;
> bool add_dso = false;
> bool add_src = false;
> + int ret = 0;
>
> if (!buf)
> return -ENOMEM;
> @@ -2653,7 +2654,8 @@ static int build_cl_output(char *cl_sort, bool no_source)
> add_dso = true;
> } else if (strcmp(tok, "offset")) {
> pr_err("unrecognized sort token: %s\n", tok);
> - return -EINVAL;
> + ret = -EINVAL;
> + goto err;
> }
> }
>
> @@ -2676,13 +2678,15 @@ static int build_cl_output(char *cl_sort, bool no_source)
> add_sym ? "symbol," : "",
> add_dso ? "dso," : "",
> add_src ? "cl_srcline," : "",
> - "node") < 0)
> - return -ENOMEM;
> + "node") < 0) {
> + ret = -ENOMEM;
> + goto err;
> + }
>
> c2c.show_src = add_src;
> -
> +err:
> free(buf);
> - return 0;
> + return ret;
> }
>
> static int setup_coalesce(const char *coalesce, bool no_source)
> --
> 2.7.4.3
>
Em Tue, Oct 15, 2019 at 10:47:53AM +0200, Jiri Olsa escreveu:
> On Tue, Oct 15, 2019 at 10:54:14AM +0800, Yunfeng Ye wrote:
> > There is a memory leak problem in the failure paths of
> > build_cl_output(), so fix it.
> >
> > Signed-off-by: Yunfeng Ye <[email protected]>
>
> Acked-by: Jiri Olsa <[email protected]>
Thanks, applied to perf/urgent.
- Arnaldo
> thanks,
> jirka
>
> > ---
> > tools/perf/builtin-c2c.c | 14 +++++++++-----
> > 1 file changed, 9 insertions(+), 5 deletions(-)
> >
> > diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
> > index 3542b6a..e69f449 100644
> > --- a/tools/perf/builtin-c2c.c
> > +++ b/tools/perf/builtin-c2c.c
> > @@ -2635,6 +2635,7 @@ static int build_cl_output(char *cl_sort, bool no_source)
> > bool add_sym = false;
> > bool add_dso = false;
> > bool add_src = false;
> > + int ret = 0;
> >
> > if (!buf)
> > return -ENOMEM;
> > @@ -2653,7 +2654,8 @@ static int build_cl_output(char *cl_sort, bool no_source)
> > add_dso = true;
> > } else if (strcmp(tok, "offset")) {
> > pr_err("unrecognized sort token: %s\n", tok);
> > - return -EINVAL;
> > + ret = -EINVAL;
> > + goto err;
> > }
> > }
> >
> > @@ -2676,13 +2678,15 @@ static int build_cl_output(char *cl_sort, bool no_source)
> > add_sym ? "symbol," : "",
> > add_dso ? "dso," : "",
> > add_src ? "cl_srcline," : "",
> > - "node") < 0)
> > - return -ENOMEM;
> > + "node") < 0) {
> > + ret = -ENOMEM;
> > + goto err;
> > + }
> >
> > c2c.show_src = add_src;
> > -
> > +err:
> > free(buf);
> > - return 0;
> > + return ret;
> > }
> >
> > static int setup_coalesce(const char *coalesce, bool no_source)
> > --
> > 2.7.4.3
> >
--
- Arnaldo
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: ae199c580da1754a2b051321eeb76d6dacd8707b
Gitweb: https://git.kernel.org/tip/ae199c580da1754a2b051321eeb76d6dacd8707b
Author: Yunfeng Ye <[email protected]>
AuthorDate: Tue, 15 Oct 2019 10:54:14 +08:00
Committer: Arnaldo Carvalho de Melo <[email protected]>
CommitterDate: Tue, 15 Oct 2019 12:08:13 -03:00
perf c2c: Fix memory leak in build_cl_output()
There is a memory leak problem in the failure paths of
build_cl_output(), so fix it.
Signed-off-by: Yunfeng Ye <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Feilong Lin <[email protected]>
Cc: Hu Shiyuan <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Link: http://lore.kernel.org/lkml/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
---
tools/perf/builtin-c2c.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 3542b6a..e69f449 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -2635,6 +2635,7 @@ static int build_cl_output(char *cl_sort, bool no_source)
bool add_sym = false;
bool add_dso = false;
bool add_src = false;
+ int ret = 0;
if (!buf)
return -ENOMEM;
@@ -2653,7 +2654,8 @@ static int build_cl_output(char *cl_sort, bool no_source)
add_dso = true;
} else if (strcmp(tok, "offset")) {
pr_err("unrecognized sort token: %s\n", tok);
- return -EINVAL;
+ ret = -EINVAL;
+ goto err;
}
}
@@ -2676,13 +2678,15 @@ static int build_cl_output(char *cl_sort, bool no_source)
add_sym ? "symbol," : "",
add_dso ? "dso," : "",
add_src ? "cl_srcline," : "",
- "node") < 0)
- return -ENOMEM;
+ "node") < 0) {
+ ret = -ENOMEM;
+ goto err;
+ }
c2c.show_src = add_src;
-
+err:
free(buf);
- return 0;
+ return ret;
}
static int setup_coalesce(const char *coalesce, bool no_source)