perf callchain: Check return value of add_child()
authorNamhyung Kim <[email protected]>
Tue, 16 Feb 2016 14:08:20 +0000 (23:08 +0900)
committerArnaldo Carvalho de Melo <[email protected]>
Fri, 19 Feb 2016 22:12:52 +0000 (19:12 -0300)
The create_child() in add_child() can return NULL in case of memory
allocation failure.  So check the return value and bail out.  The proper
error handling will be added later.

Signed-off-by: Namhyung Kim <[email protected]>
Acked-by: Jiri Olsa <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: Wang Nan <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
tools/perf/util/callchain.c

index 53c43eb9489e4ba4a4e56a795bc05c2b85fb4cbc..134d88b33fc19a77f4f253a5358ae923ad4a65ed 100644 (file)
@@ -453,6 +453,9 @@ add_child(struct callchain_node *parent,
        struct callchain_node *new;
 
        new = create_child(parent, false);
+       if (new == NULL)
+               return NULL;
+
        fill_node(new, cursor);
 
        new->children_hit = 0;
@@ -524,6 +527,8 @@ split_add_child(struct callchain_node *parent,
 
                node = callchain_cursor_current(cursor);
                new = add_child(parent, cursor, period);
+               if (new == NULL)
+                       return;
 
                /*
                 * This is second child since we moved parent's children
@@ -585,6 +590,9 @@ append_chain_children(struct callchain_node *root,
        }
        /* nothing in children, add to the current node */
        rnode = add_child(root, cursor, period);
+       if (rnode == NULL)
+               return;
+
        rb_link_node(&rnode->rb_node_in, parent, p);
        rb_insert_color(&rnode->rb_node_in, &root->rb_root_in);