From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758467AbcBTLk0 (ORCPT ); Sat, 20 Feb 2016 06:40:26 -0500 Received: from terminus.zytor.com ([198.137.202.10]:38270 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758431AbcBTLkX (ORCPT ); Sat, 20 Feb 2016 06:40:23 -0500 Date: Sat, 20 Feb 2016 03:39:43 -0800 From: tip-bot for Namhyung Kim Message-ID: Cc: mingo@kernel.org, acme@redhat.com, fweisbec@gmail.com, linux-kernel@vger.kernel.org, eranian@google.com, namhyung@kernel.org, peterz@infradead.org, tglx@linutronix.de, hpa@zytor.com, jolsa@kernel.org, andi@firstfloor.org, dsahern@gmail.com, wangnan0@huawei.com Reply-To: mingo@kernel.org, fweisbec@gmail.com, acme@redhat.com, linux-kernel@vger.kernel.org, eranian@google.com, namhyung@kernel.org, peterz@infradead.org, dsahern@gmail.com, wangnan0@huawei.com, andi@firstfloor.org, tglx@linutronix.de, jolsa@kernel.org, hpa@zytor.com In-Reply-To: <1455631723-17345-4-git-send-email-namhyung@kernel.org> References: <1455631723-17345-4-git-send-email-namhyung@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf callchain: Check return value of fill_node() Git-Commit-ID: 8451cbb9b174a9b6e016d7f1bff81ff12dbd1990 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: 8451cbb9b174a9b6e016d7f1bff81ff12dbd1990 Gitweb: http://git.kernel.org/tip/8451cbb9b174a9b6e016d7f1bff81ff12dbd1990 Author: Namhyung Kim AuthorDate: Tue, 16 Feb 2016 23:08:21 +0900 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 19 Feb 2016 19:13:21 -0300 perf callchain: Check return value of fill_node() Memory allocation in the fill_node() can fail so change its return type to int and check it in add_child() too. Signed-off-by: Namhyung Kim Acked-by: Jiri Olsa Cc: Andi Kleen Cc: David Ahern Cc: Frederic Weisbecker Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Wang Nan Link: http://lkml.kernel.org/r/1455631723-17345-4-git-send-email-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/callchain.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/callchain.c b/tools/perf/util/callchain.c index 134d88b..a82ea6f 100644 --- a/tools/perf/util/callchain.c +++ b/tools/perf/util/callchain.c @@ -416,7 +416,7 @@ create_child(struct callchain_node *parent, bool inherit_children) /* * Fill the node with callchain values */ -static void +static int fill_node(struct callchain_node *node, struct callchain_cursor *cursor) { struct callchain_cursor_node *cursor_node; @@ -433,7 +433,7 @@ fill_node(struct callchain_node *node, struct callchain_cursor *cursor) call = zalloc(sizeof(*call)); if (!call) { perror("not enough memory for the code path tree"); - return; + return -1; } call->ip = cursor_node->ip; call->ms.sym = cursor_node->sym; @@ -443,6 +443,7 @@ fill_node(struct callchain_node *node, struct callchain_cursor *cursor) callchain_cursor_advance(cursor); cursor_node = callchain_cursor_current(cursor); } + return 0; } static struct callchain_node * @@ -456,7 +457,16 @@ add_child(struct callchain_node *parent, if (new == NULL) return NULL; - fill_node(new, cursor); + if (fill_node(new, cursor) < 0) { + struct callchain_list *call, *tmp; + + list_for_each_entry_safe(call, tmp, &new->val, list) { + list_del(&call->list); + free(call); + } + free(new); + return NULL; + } new->children_hit = 0; new->hit = period;