diff options
author | Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> | 2014-01-16 04:39:44 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-01-16 14:26:50 -0500 |
commit | 981d05adf2e2acc328abb929a6ed3536c0d41c5f (patch) | |
tree | 0382a51e80b8f2f5db12264ab2964b996c05d51e /tools/perf | |
parent | a7077234d240f16ead29ffeb3cc17ceada50ea5f (diff) |
perf probe: Release allocated probe_trace_event if failed
To fix a memory leak, release all allocated probe_trace_event on the
error path of try_to_find_probe_trace_events.
Reported-by: David Ahern <dsahern@gmail.com>
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: "David A. Long" <dave.long@linaro.org>
Cc: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: yrl.pp-manager.tt@hitachi.com
Link: http://lkml.kernel.org/r/20140116093944.24403.30228.stgit@kbuild-fedora.novalocal
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/util/probe-event.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index a4ee6b4a840f..579b655c0f93 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
@@ -72,6 +72,7 @@ static int e_snprintf(char *str, size_t size, const char *format, ...) | |||
72 | static char *synthesize_perf_probe_point(struct perf_probe_point *pp); | 72 | static char *synthesize_perf_probe_point(struct perf_probe_point *pp); |
73 | static int convert_name_to_addr(struct perf_probe_event *pev, | 73 | static int convert_name_to_addr(struct perf_probe_event *pev, |
74 | const char *exec); | 74 | const char *exec); |
75 | static void clear_probe_trace_event(struct probe_trace_event *tev); | ||
75 | static struct machine machine; | 76 | static struct machine machine; |
76 | 77 | ||
77 | /* Initialize symbol maps and path of vmlinux/modules */ | 78 | /* Initialize symbol maps and path of vmlinux/modules */ |
@@ -407,6 +408,14 @@ static int add_module_to_probe_trace_events(struct probe_trace_event *tevs, | |||
407 | return ret; | 408 | return ret; |
408 | } | 409 | } |
409 | 410 | ||
411 | static void clear_probe_trace_events(struct probe_trace_event *tevs, int ntevs) | ||
412 | { | ||
413 | int i; | ||
414 | |||
415 | for (i = 0; i < ntevs; i++) | ||
416 | clear_probe_trace_event(tevs + i); | ||
417 | } | ||
418 | |||
410 | /* Try to find perf_probe_event with debuginfo */ | 419 | /* Try to find perf_probe_event with debuginfo */ |
411 | static int try_to_find_probe_trace_events(struct perf_probe_event *pev, | 420 | static int try_to_find_probe_trace_events(struct perf_probe_event *pev, |
412 | struct probe_trace_event **tevs, | 421 | struct probe_trace_event **tevs, |
@@ -442,6 +451,10 @@ static int try_to_find_probe_trace_events(struct perf_probe_event *pev, | |||
442 | ret = add_module_to_probe_trace_events(*tevs, | 451 | ret = add_module_to_probe_trace_events(*tevs, |
443 | ntevs, target); | 452 | ntevs, target); |
444 | } | 453 | } |
454 | if (ret < 0) { | ||
455 | clear_probe_trace_events(*tevs, ntevs); | ||
456 | zfree(tevs); | ||
457 | } | ||
445 | return ret < 0 ? ret : ntevs; | 458 | return ret < 0 ? ret : ntevs; |
446 | } | 459 | } |
447 | 460 | ||