Skip to content

Commit

Permalink
perf probe: Free string returned by synthesize_perf_probe_point() on …
Browse files Browse the repository at this point in the history
…failure in synthesize_perf_probe_command()

Building perf with EXTRA_CFLAGS="-fsanitize=address" a leak was detected
elsewhere and lead to an audit, where we found that
synthesize_perf_probe_command() may leak synthesize_perf_probe_point()
return on failure, fix it.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/lkml/ZM0mzpQktHnhXJXr@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Arnaldo Carvalho de Melo committed Aug 7, 2023
1 parent 7bc0153 commit a612bbf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tools/perf/util/probe-event.c
Original file line number Diff line number Diff line change
Expand Up @@ -2063,14 +2063,18 @@ char *synthesize_perf_probe_command(struct perf_probe_event *pev)
goto out;

tmp = synthesize_perf_probe_point(&pev->point);
if (!tmp || strbuf_addstr(&buf, tmp) < 0)
if (!tmp || strbuf_addstr(&buf, tmp) < 0) {
free(tmp);
goto out;
}
free(tmp);

for (i = 0; i < pev->nargs; i++) {
tmp = synthesize_perf_probe_arg(pev->args + i);
if (!tmp || strbuf_addf(&buf, " %s", tmp) < 0)
if (!tmp || strbuf_addf(&buf, " %s", tmp) < 0) {
free(tmp);
goto out;
}
free(tmp);
}

Expand Down

0 comments on commit a612bbf

Please sign in to comment.