When splicing out a node we set the ->parent pointer of all child
nodes to the parent of the given node, and move each child to the
->children list of the parent.
Except when there is no parent. If the given node was a root node
(or an internal node whose parent vanished), we leave the ->children
list untouched. In this case the assertion a few lines later triggers
and aborts the program. Fix this by removing the nodes from the list.
Such nodes have become root nodes themselves, so they should not be
on any list of children.
ch->parent = btrn->parent;
if (btrn->parent)
list_move(&ch->node, &btrn->parent->children);
+ else
+ list_del(&ch->node);
}
assert(list_empty(&btrn->children));
btrn->parent = NULL;