Skip to content

Commit 0196e78

Browse files
mhiramathitachiacmel
authored andcommitted
perf probe: Fix memory leaking on failure by clearing all probe_trace_events
Fix memory leaking on the debuginfo__find_trace_events() failure path which frees an array of probe_trace_events but doesn't clears all the allocated sub-structures and strings. So, before doing zfree(tevs), clear all the array elements which may have allocated resources. Reported-by: Wang Nan <[email protected]> Signed-off-by: Masami Hiramatsu <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Zefan Li <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent d8145b3 commit 0196e78

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tools/perf/util/probe-finder.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ int debuginfo__find_trace_events(struct debuginfo *dbg,
12461246
struct trace_event_finder tf = {
12471247
.pf = {.pev = pev, .callback = add_probe_trace_event},
12481248
.max_tevs = probe_conf.max_probes, .mod = dbg->mod};
1249-
int ret;
1249+
int ret, i;
12501250

12511251
/* Allocate result tevs array */
12521252
*tevs = zalloc(sizeof(struct probe_trace_event) * tf.max_tevs);
@@ -1258,6 +1258,8 @@ int debuginfo__find_trace_events(struct debuginfo *dbg,
12581258

12591259
ret = debuginfo__find_probes(dbg, &tf.pf);
12601260
if (ret < 0) {
1261+
for (i = 0; i < tf.ntevs; i++)
1262+
clear_probe_trace_event(&tf.tevs[i]);
12611263
zfree(tevs);
12621264
return ret;
12631265
}

0 commit comments

Comments
 (0)