Re: [PATCH] perf tools: Fix possible double free on error

From: He Kuang
Date: Mon Mar 09 2015 - 23:36:59 EST


It seems this patch not appeared in any repo, so ping..

On 2015/3/4 20:46, Masami Hiramatsu wrote:
(2015/03/04 19:01), He Kuang wrote:
A double free occurred when get source file path failed. If lr->path
failed to assign a new value, it will be freed as the old path and then
be freed again during line_range__clear(), and causes this:

$ perf probe -L do_execve -k vmlinux
*** Error in `/usr/bin/perf': double free or corruption (fasttop):
0x0000000000a9ac50 ***
======= Backtrace: =========

This patch fix this problem.
Good catch!

Acked-by: Masami Hiramatsu <>

Thank you,

Signed-off-by: He Kuang <hekuang@xxxxxxxxxx>
tools/perf/util/probe-event.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 919937e..7df30bd 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -650,7 +650,11 @@ static int __show_line_range(struct line_range *lr, const char *module)
/* Convert source file path */
tmp = lr->path;
ret = get_real_path(tmp, lr->comp_dir, &lr->path);
- free(tmp); /* Free old path */
+ /* Free old path when new path is assigned */
+ if (tmp != lr->path)
+ free(tmp);
if (ret < 0) {
pr_warning("Failed to find source file path.\n");
return ret;

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at