struct callchain_node *new;
 
        new = create_child(parent, false);
+       if (new == NULL)
+               return NULL;
+
        fill_node(new, cursor);
 
        new->children_hit = 0;
 
                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
        }
        /* 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);