Skip to content

Commit

Permalink
perf probe: Fix memory leak when synthesizing SDT probes
Browse files Browse the repository at this point in the history
The argv_split() function must be paired with argv_free(), else we must
keep a reference to the argv array received or do the freeing ourselves,
in synthesize_sdt_probe_command() we were simply leaking that argv[]
array.

Fixes: 3b1f831 ("perf probe: Add sdt probes arguments into the uprobe cmd string")
Cc: Adrian Hunter <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Alexandre Truong <[email protected]>
Cc: Alexis Berlemont <[email protected]>
Cc: He Zhe <[email protected]>
Cc: Ian Rogers <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: John Garry <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Masami Hiramatsu <[email protected]>
Cc: Mathieu Poirier <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Sumanth Korikkar <[email protected]>
Cc: Thomas Richter <[email protected]>
Cc: Will Deacon <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
acmel committed Dec 24, 2020
1 parent 8d4852b commit 5149303
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tools/perf/util/probe-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note,
const char *sdtgrp)
{
struct strbuf buf;
char *ret = NULL, **args;
char *ret = NULL;
int i, args_count, err;
unsigned long long ref_ctr_offset;

Expand All @@ -813,12 +813,19 @@ static char *synthesize_sdt_probe_command(struct sdt_note *note,
goto out;

if (note->args) {
args = argv_split(note->args, &args_count);
char **args = argv_split(note->args, &args_count);

if (args == NULL)
goto error;

for (i = 0; i < args_count; ++i) {
if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0)
if (synthesize_sdt_probe_arg(&buf, i, args[i]) < 0) {
argv_free(args);
goto error;
}
}

argv_free(args);
}

out:
Expand Down

0 comments on commit 5149303

Please sign in to comment.