Skip to content

Commit 5ecab78

Browse files
captain5050acmel
authored andcommitted
perf lock: Avoid memory leaks from strdup()
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/[email protected]/ Suggested-by: Namhyung Kim <[email protected]> Signed-off-by: Ian Rogers <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: zhaimingbing <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 6fe61cb commit 5ecab78

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

tools/perf/builtin-lock.c

+4-14
Original file line numberDiff line numberDiff line change
@@ -2275,23 +2275,13 @@ static int __cmd_record(int argc, const char **argv)
22752275
return -ENOMEM;
22762276

22772277
for (i = 0; i < ARRAY_SIZE(record_args); i++)
2278-
rec_argv[i] = strdup(record_args[i]);
2278+
rec_argv[i] = record_args[i];
22792279

22802280
for (j = 0; j < nr_tracepoints; j++) {
2281-
const char *ev_name;
2282-
2283-
if (has_lock_stat)
2284-
ev_name = strdup(lock_tracepoints[j].name);
2285-
else
2286-
ev_name = strdup(contention_tracepoints[j].name);
2287-
2288-
if (!ev_name) {
2289-
free(rec_argv);
2290-
return -ENOMEM;
2291-
}
2292-
22932281
rec_argv[i++] = "-e";
2294-
rec_argv[i++] = ev_name;
2282+
rec_argv[i++] = has_lock_stat
2283+
? lock_tracepoints[j].name
2284+
: contention_tracepoints[j].name;
22952285
}
22962286

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

0 commit comments

Comments
 (0)