From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756991AbbCNHFA (ORCPT ); Sat, 14 Mar 2015 03:05:00 -0400 Received: from terminus.zytor.com ([198.137.202.10]:40244 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751222AbbCNHEy (ORCPT ); Sat, 14 Mar 2015 03:04:54 -0400 Date: Sat, 14 Mar 2015 00:04:33 -0700 From: tip-bot for He Kuang Message-ID: Cc: mingo@redhat.com, linux-kernel@vger.kernel.org, masami.hiramatsu.pt@hitachi.com, a.p.zijlstra@chello.nl, acme@redhat.com, hekuang@huawei.com, wangnan0@huawei.com, tglx@linutronix.de, mingo@kernel.org, hpa@zytor.com Reply-To: hekuang@huawei.com, a.p.zijlstra@chello.nl, acme@redhat.com, masami.hiramatsu.pt@hitachi.com, linux-kernel@vger.kernel.org, mingo@redhat.com, hpa@zytor.com, mingo@kernel.org, tglx@linutronix.de, wangnan0@huawei.com In-Reply-To: <1425463302-1687-1-git-send-email-hekuang@huawei.com> References: <1425463302-1687-1-git-send-email-hekuang@huawei.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf probe: Fix possible double free on error Git-Commit-ID: a78604defffbc1da1497a8c8b48275b723eb5946 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: a78604defffbc1da1497a8c8b48275b723eb5946 Gitweb: http://git.kernel.org/tip/a78604defffbc1da1497a8c8b48275b723eb5946 Author: He Kuang AuthorDate: Wed, 4 Mar 2015 18:01:42 +0800 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 12 Mar 2015 12:39:58 -0300 perf probe: Fix possible double free on error 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: ========= ../lib64/libc.so.6(+0x6eeef)[0x7ffff5e44eef] ../lib64/libc.so.6(+0x78cae)[0x7ffff5e4ecae] ../lib64/libc.so.6(+0x79987)[0x7ffff5e4f987] ../bin/perf[0x4ab41f] ... This patch fix this problem. Signed-off-by: He Kuang Acked-by: Masami Hiramatsu Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Wang Nan Link: http://lkml.kernel.org/r/1425463302-1687-1-git-send-email-hekuang@huawei.com Signed-off-by: Arnaldo Carvalho de Melo --- 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 8af8e7f..e2bf620 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c @@ -790,7 +790,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;