Skip to content

Commit ae199c5

Browse files
yeyunfeng-devacmel
authored andcommitted
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]>
1 parent 5a0baf5 commit ae199c5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

tools/perf/builtin-c2c.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,6 +2635,7 @@ static int build_cl_output(char *cl_sort, bool no_source)
26352635
bool add_sym = false;
26362636
bool add_dso = false;
26372637
bool add_src = false;
2638+
int ret = 0;
26382639

26392640
if (!buf)
26402641
return -ENOMEM;
@@ -2653,7 +2654,8 @@ static int build_cl_output(char *cl_sort, bool no_source)
26532654
add_dso = true;
26542655
} else if (strcmp(tok, "offset")) {
26552656
pr_err("unrecognized sort token: %s\n", tok);
2656-
return -EINVAL;
2657+
ret = -EINVAL;
2658+
goto err;
26572659
}
26582660
}
26592661

@@ -2676,13 +2678,15 @@ static int build_cl_output(char *cl_sort, bool no_source)
26762678
add_sym ? "symbol," : "",
26772679
add_dso ? "dso," : "",
26782680
add_src ? "cl_srcline," : "",
2679-
"node") < 0)
2680-
return -ENOMEM;
2681+
"node") < 0) {
2682+
ret = -ENOMEM;
2683+
goto err;
2684+
}
26812685

26822686
c2c.show_src = add_src;
2683-
2687+
err:
26842688
free(buf);
2685-
return 0;
2689+
return ret;
26862690
}
26872691

26882692
static int setup_coalesce(const char *coalesce, bool no_source)

0 commit comments

Comments
 (0)