[PATCH] perf lock: Fix a memory leak on an error path

From: zhaimingbing
Date: Fri Nov 24 2023 - 04:27:12 EST


if a strdup-ed string is NULL,the allocated memory needs freeing.

Signed-off-by: zhaimingbing <zhaimingbing@xxxxxxxxxxxxxxxxxxxx>
---
tools/perf/builtin-lock.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
index b141f2134..086041bcb 100644
--- a/tools/perf/builtin-lock.c
+++ b/tools/perf/builtin-lock.c
@@ -2228,8 +2228,10 @@ static int __cmd_record(int argc, const char **argv)
else
ev_name = strdup(contention_tracepoints[j].name);

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

rec_argv[i++] = "-e";
rec_argv[i++] = ev_name;
--
2.33.0