]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 29 Dec 2020 12:42:41 +0000 (13:42 +0100)
[ Upstream commit 2eb5dd418034ecea2f7031e3d33f2991a878b148 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
tools/perf/util/parse-regs-options.c

index 4f2c1c255d818bcf0b13a05d806ddb04fcbd2ff5..a8865d1c3e818d8c9c824381796427a56c82d1cc 100644 (file)
@@ -40,7 +40,7 @@ parse_regs(const struct option *opt, const char *str, int unset)
                                }
                                fputc('\n', stderr);
                                /* just printing available regs */
-                               return -1;
+                               goto error;
                        }
                        for (r = sample_reg_masks; r->name; r++) {
                                if (!strcasecmp(s, r->name))