Skip to content

Commit 908d50e

Browse files
Li Huafeinamhyung
authored andcommitted
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: c5d60de ("perf annotate: Add support to use libcapstone in powerpc") Signed-off-by: Li Huafei <[email protected]> Tested-by: Athira Rajeev <[email protected]> Cc: [email protected] Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent b4e0e9a commit 908d50e

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

tools/perf/util/disasm.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,7 @@ static int symbol__disassemble_capstone_powerpc(char *filename, struct symbol *s
15731573

15741574
dl = disasm_line__new(args);
15751575
if (dl == NULL)
1576-
goto err;
1576+
break;
15771577

15781578
annotation_line__add(&dl->al, &notes->src->source);
15791579

@@ -1603,18 +1603,6 @@ static int symbol__disassemble_capstone_powerpc(char *filename, struct symbol *s
16031603
err:
16041604
if (fd >= 0)
16051605
close(fd);
1606-
if (needs_cs_close) {
1607-
struct disasm_line *tmp;
1608-
1609-
/*
1610-
* It probably failed in the middle of the above loop.
1611-
* Release any resources it might add.
1612-
*/
1613-
list_for_each_entry_safe(dl, tmp, &notes->src->source, al.node) {
1614-
list_del(&dl->al.node);
1615-
free(dl);
1616-
}
1617-
}
16181606
count = -1;
16191607
goto out;
16201608
}

0 commit comments

Comments
 (0)