Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf probe: Free string returned by synthesize_perf_probe_point() on 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>

+6 -2
+6 -2
tools/perf/util/probe-event.c
··· 2063 2063 goto out; 2064 2064 2065 2065 tmp = synthesize_perf_probe_point(&pev->point); 2066 - if (!tmp || strbuf_addstr(&buf, tmp) < 0) 2066 + if (!tmp || strbuf_addstr(&buf, tmp) < 0) { 2067 + free(tmp); 2067 2068 goto out; 2069 + } 2068 2070 free(tmp); 2069 2071 2070 2072 for (i = 0; i < pev->nargs; i++) { 2071 2073 tmp = synthesize_perf_probe_arg(pev->args + i); 2072 - if (!tmp || strbuf_addf(&buf, " %s", tmp) < 0) 2074 + if (!tmp || strbuf_addf(&buf, " %s", tmp) < 0) { 2075 + free(tmp); 2073 2076 goto out; 2077 + } 2074 2078 free(tmp); 2075 2079 } 2076 2080