Skip to content

Commit

Permalink
perf probe: Avoid calling freeing routine multiple times for same poi…
Browse files Browse the repository at this point in the history
…nter

When perf_add_probe_events() we call cleanup_perf_probe_events() for the
pev pointer it receives, then, as part of handling this failure the main
'perf probe' goes on and calls cleanup_params() and that will again call
cleanup_perf_probe_events()for the same pointer, so just set nevents to
zero when handling the failure of perf_add_probe_events() to avoid the
double free.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lkml.kernel.org/n/tip-x8qgma4g813z96dvtw9w219q@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Arnaldo Carvalho de Melo committed Jul 23, 2019
1 parent df8350e commit d95daf5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tools/perf/builtin-probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,16 @@ __cmd_probe(int argc, const char **argv)

ret = perf_add_probe_events(params.events, params.nevents);
if (ret < 0) {

/*
* When perf_add_probe_events() fails it calls
* cleanup_perf_probe_events(pevs, npevs), i.e.
* cleanup_perf_probe_events(params.events, params.nevents), which
* will call clear_perf_probe_event(), so set nevents to zero
* to avoid cleanup_params() to call clear_perf_probe_event() again
* on the same pevs.
*/
params.nevents = 0;
pr_err_with_code(" Error: Failed to add events.", ret);
return ret;
}
Expand Down

0 comments on commit d95daf5

Please sign in to comment.