Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf record: Fix memory leak when using '--user-regs=?' to list registers

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>

authored by

Zheng Zengkai and committed by
Arnaldo Carvalho de Melo
2eb5dd41 09d59c2f

+1 -1
+1 -1
tools/perf/util/parse-regs-options.c
··· 54 54 #endif 55 55 fputc('\n', stderr); 56 56 /* just printing available regs */ 57 - return -1; 57 + goto error; 58 58 } 59 59 #ifdef HAVE_PERF_REGS_SUPPORT 60 60 for (r = sample_reg_masks; r->name; r++) {