Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1324169

[PATCH 02/21] perf callchain: Check return value of fill_node()

From Namhyung Kim <namhyung@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 02/21] perf callchain: Check return value of fill_node()
Date 2016-02-02 15:50 +0100
Message-ID <qXKri-4kd-73@gated-at.bofh.it> (permalink)
References <qXKrf-4kd-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Memory allocation in the fill_node() can fail so change its return type
to int and check it in add_child() too.

Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
 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 134d88b33fc1..a82ea6f6fc0f 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;
-- 
2.6.4

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCHSET 00/21] perf tools: Add support for hierachy view (v4) Namhyung Kim <namhyung@kernel.org> - 2016-02-02 15:50 +0100
  [PATCH 04/21] perf callchain: Check return value of split_add_child() Namhyung Kim <namhyung@kernel.org> - 2016-02-02 15:50 +0100
  [PATCH 10/21] perf hists: Add helper functions for hierarchy mode Namhyung Kim <namhyung@kernel.org> - 2016-02-02 15:50 +0100
  [PATCH 15/21] perf hists browser: Support collapsing/expanding whole entries in hierarchy Namhyung Kim <namhyung@kernel.org> - 2016-02-02 15:50 +0100
  [PATCH 09/21] perf hists: Resort hist entries with hierarchy Namhyung Kim <namhyung@kernel.org> - 2016-02-02 15:50 +0100
  [PATCH 12/21] perf ui/stdio: Implement hierarchy output mode Namhyung Kim <namhyung@kernel.org> - 2016-02-02 15:50 +0100
  [PATCH 05/21] perf callchain: Check return value of append_chain_children() Namhyung Kim <namhyung@kernel.org> - 2016-02-02 15:50 +0100
  [PATCH 18/21] perf ui/gtk: Implement hierarchy output mode Namhyung Kim <namhyung@kernel.org> - 2016-02-02 15:50 +0100
  [PATCH 17/21] perf hists browser: Align column header in hierarchy mode Namhyung Kim <namhyung@kernel.org> - 2016-02-02 15:50 +0100
  [PATCH 21/21] perf top: Add --hierarchy option Namhyung Kim <namhyung@kernel.org> - 2016-02-02 15:50 +0100
  [PATCH 02/21] perf callchain: Check return value of fill_node() Namhyung Kim <namhyung@kernel.org> - 2016-02-02 15:50 +0100

csiph-web