diff --git a/tree_alloc.c b/tree_alloc.c index ce2b9d7..d06c8de 100644 --- a/tree_alloc.c +++ b/tree_alloc.c @@ -169,7 +169,7 @@ void replace_node(TreeAlloc **root_ptr, TreeAlloc *node, TreeAlloc *replace) { else node->parent->right = replace; } - if (!replace) replace->parent = node->parent; + if (replace) replace->parent = node->parent; } void repair_after_remove(TreeAlloc **root_ptr, TreeAlloc *node) { @@ -242,7 +242,7 @@ void remove_node(TreeAlloc **root_ptr, TreeAlloc *node) { node->left->parent = tmp; } - if (do_repair) { + if (do_repair && replace) { repair_after_remove(root_ptr, replace); } }