Skip to content

Commit 54ef362

Browse files
committed
perf callchain: Use zfree() to avoid possibly accessing dangling pointers
When freeing a->b it is good practice to set a->b to NULL using zfree(&a->b) so that when we have a bug where a reference to a freed 'a' pointer is kept somewhere, we can more quickly cause a segfault if some code tries to use a->b. Convert one such case in the callchain code. Cc: Adrian Hunter <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Namhyung Kim <[email protected]> Link: https://lore.kernel.org/lkml/ZjmcGobQ8E52EyjJ@x1 Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 69fb6ea commit 54ef362

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/perf/util/callchain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ fill_node(struct callchain_node *node, struct callchain_cursor *cursor)
606606
call->brtype_stat = zalloc(sizeof(*call->brtype_stat));
607607
if (!call->brtype_stat) {
608608
perror("not enough memory for the code path branch statistics");
609-
free(call->brtype_stat);
609+
zfree(&call->brtype_stat);
610610
return -ENOMEM;
611611
}
612612
}

0 commit comments

Comments
 (0)