[PATCH 2/3] perf disasm: Use disasm_line__free() to properly free disasm_line
From: Li Huafei
Date: Sun Oct 13 2024 - 23:42:48 EST
The structure disasm_line contains members that require dynamically
allocated memory and need to be freed correctly using
disasm_line__free().
This patch fixes the incorrect freeing in
symbol__disassemble_capstone_powerpc(). Also, since cs_disasm is not
enabled, it does not need to handle the situation described in
symbol__disassemble_capstone() where "offset != len" may occur due to
unknown instructions.
Fixes: c5d60de1813a ("perf annotate: Add support to use libcapstone in powerpc")
Signed-off-by: Li Huafei <lihuafei1@xxxxxxxxxx>
---
tools/perf/util/disasm.c | 16 +---------------
1 file changed, 1 insertion(+), 15 deletions(-)
diff --git a/tools/perf/util/disasm.c b/tools/perf/util/disasm.c
index 42222d61ceb5..40d99f4d5cc7 100644
--- a/tools/perf/util/disasm.c
+++ b/tools/perf/util/disasm.c
@@ -1580,20 +1580,6 @@ static int symbol__disassemble_capstone_powerpc(char *filename, struct symbol *s
offset += 4;
}
- /* It failed in the middle */
- if (offset != len) {
- struct list_head *list = ¬es->src->source;
-
- /* Discard all lines and fallback to objdump */
- while (!list_empty(list)) {
- dl = list_first_entry(list, struct disasm_line, al.node);
-
- list_del_init(&dl->al.node);
- disasm_line__free(dl);
- }
- count = -1;
- }
-
out:
if (needs_cs_close)
cs_close(&handle);
@@ -1612,7 +1598,7 @@ static int symbol__disassemble_capstone_powerpc(char *filename, struct symbol *s
*/
list_for_each_entry_safe(dl, tmp, ¬es->src->source, al.node) {
list_del(&dl->al.node);
- free(dl);
+ disasm_line__free(dl);
}
}
count = -1;
--
2.25.1