mirror of
https://github.com/torvalds/linux.git
synced 2026-05-23 22:52:19 +02:00
perf disasm: Use disasm_line__free() to properly free disasm_line
symbol__disassemble_capstone_powerpc() goto the 'err' label when it
failed in the loop that created disasm_line, and then used free()
directly to free disasm_line. Since the structure disasm_line contains
members that allocate memory dynamically, this can result in a memory
leak. In fact, we can simply break the loop when it fails in the middle
of the loop, and disasm_line__free() will then be called to properly
free the created line. Other error paths do not need to consider freeing
disasm_line.
Fixes: c5d60de181 ("perf annotate: Add support to use libcapstone in powerpc")
Signed-off-by: Li Huafei <lihuafei1@huawei.com>
Tested-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: sesse@google.com
Cc: kjain@linux.ibm.com
Link: https://lore.kernel.org/r/20241019154157.282038-2-lihuafei1@huawei.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
parent
b4e0e9a1e3
commit
908d50e50e
|
|
@ -1573,7 +1573,7 @@ static int symbol__disassemble_capstone_powerpc(char *filename, struct symbol *s
|
|||
|
||||
dl = disasm_line__new(args);
|
||||
if (dl == NULL)
|
||||
goto err;
|
||||
break;
|
||||
|
||||
annotation_line__add(&dl->al, ¬es->src->source);
|
||||
|
||||
|
|
@ -1603,18 +1603,6 @@ static int symbol__disassemble_capstone_powerpc(char *filename, struct symbol *s
|
|||
err:
|
||||
if (fd >= 0)
|
||||
close(fd);
|
||||
if (needs_cs_close) {
|
||||
struct disasm_line *tmp;
|
||||
|
||||
/*
|
||||
* It probably failed in the middle of the above loop.
|
||||
* Release any resources it might add.
|
||||
*/
|
||||
list_for_each_entry_safe(dl, tmp, ¬es->src->source, al.node) {
|
||||
list_del(&dl->al.node);
|
||||
free(dl);
|
||||
}
|
||||
}
|
||||
count = -1;
|
||||
goto out;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user