perf record: Fix memory leak when using '--user-regs=?' to list registers
authorZheng Zengkai <zhengzengkai@huawei.com>
Fri, 3 Jul 2020 09:33:44 +0000 (17:33 +0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 17 Dec 2020 17:36:16 +0000 (14:36 -0300)
When using 'perf record's option '-I' or '--user-regs=' along with
argument '?' to list available register names, memory of variable 'os'
allocated by strdup() needs to be released before __parse_regs()
returns, otherwise memory leak will occur.

Fixes: bcc84ec65ad1 ("perf record: Add ability to name registers to record")
Signed-off-by: Zheng Zengkai <zhengzengkai@huawei.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Li Bin <huawei.libin@huawei.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20200703093344.189450-1-zhengzengkai@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/parse-regs-options.c

index e687497..a4a1004 100644 (file)
@@ -54,7 +54,7 @@ __parse_regs(const struct option *opt, const char *str, int unset, bool intr)
 #endif
                                fputc('\n', stderr);
                                /* just printing available regs */
-                               return -1;
+                               goto error;
                        }
 #ifdef HAVE_PERF_REGS_SUPPORT
                        for (r = sample_reg_masks; r->name; r++) {