Skip to content

Commit

Permalink
perf lock: Avoid memory leaks from strdup()
Browse files Browse the repository at this point in the history
Leak sanitizer complains about the strdup-ed arguments not being freed
and given cmd_record doesn't modify the given strings, remove the
strdups.

Original discussion in this patch:

  https://lore.kernel.org/lkml/20240430184156.1824083-1-irogers@google.com/

Suggested-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: zhaimingbing <zhaimingbing@cmss.chinamobile.com>
Link: https://lore.kernel.org/r/20240509053123.1918093-1-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
Ian Rogers authored and Arnaldo Carvalho de Melo committed May 10, 2024
1 parent 6fe61cb commit 5ecab78
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions tools/perf/builtin-lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -2275,23 +2275,13 @@ static int __cmd_record(int argc, const char **argv)
return -ENOMEM;

for (i = 0; i < ARRAY_SIZE(record_args); i++)
rec_argv[i] = strdup(record_args[i]);
rec_argv[i] = record_args[i];

for (j = 0; j < nr_tracepoints; j++) {
const char *ev_name;

if (has_lock_stat)
ev_name = strdup(lock_tracepoints[j].name);
else
ev_name = strdup(contention_tracepoints[j].name);

if (!ev_name) {
free(rec_argv);
return -ENOMEM;
}

rec_argv[i++] = "-e";
rec_argv[i++] = ev_name;
rec_argv[i++] = has_lock_stat
? lock_tracepoints[j].name
: contention_tracepoints[j].name;
}

for (j = 0; j < nr_callgraph_args; j++, i++)
Expand Down

0 comments on commit 5ecab78

Please sign in to comment.