diff options
author | Ian Rogers <[email protected]> | 2024-10-16 16:56:21 -0700 |
---|---|---|
committer | Namhyung Kim <[email protected]> | 2024-10-17 12:43:14 -0700 |
commit | 1280f012e06e1555de47e3c3a9be898d8cbda5fb (patch) | |
tree | 80abc25771ed55bc63f320fe6d9dd007d11bcef5 | |
parent | 54f9aa109245717df95d8dd2a1f42a3f42abdd3b (diff) |
perf disasm: Fix capstone memory leak
The insn argument passed to cs_disasm needs freeing. To support
accurately having count, add an additional free_count variable.
Fixes: c5d60de1813a ("perf annotate: Add support to use libcapstone in powerpc")
Signed-off-by: Ian Rogers <[email protected]>
Reviewed-by: James Clark <[email protected]>
Cc: David S. Miller <[email protected]>
Cc: Steinar H. Gunderson <[email protected]>
Cc: Alexander Lobakin <[email protected]>
Cc: Masami Hiramatsu (Google) <[email protected]>
Cc: Kajol Jain <[email protected]>
Cc: Athira Rajeev <[email protected]>
Cc: Hemant Kumar <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Namhyung Kim <[email protected]>
-rw-r--r-- | tools/perf/util/disasm.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c index f05ba7739c1e..2c8063660f2e 100644 --- a/tools/perf/util/disasm.c +++ b/tools/perf/util/disasm.c @@ -1627,12 +1627,12 @@ static int symbol__disassemble_capstone(char *filename, struct symbol *sym, u64 start = map__rip_2objdump(map, sym->start); u64 len; u64 offset; - int i, count; + int i, count, free_count; bool is_64bit = false; bool needs_cs_close = false; u8 *buf = NULL; csh handle; - cs_insn *insn; + cs_insn *insn = NULL; char disasm_buf[512]; struct disasm_line *dl; @@ -1664,7 +1664,7 @@ static int symbol__disassemble_capstone(char *filename, struct symbol *sym, needs_cs_close = true; - count = cs_disasm(handle, buf, len, start, len, &insn); + free_count = count = cs_disasm(handle, buf, len, start, len, &insn); for (i = 0, offset = 0; i < count; i++) { int printed; @@ -1702,8 +1702,11 @@ static int symbol__disassemble_capstone(char *filename, struct symbol *sym, } out: - if (needs_cs_close) + if (needs_cs_close) { cs_close(&handle); + if (free_count > 0) + cs_free(insn, free_count); + } free(buf); return count < 0 ? count : 0; |