Correct memory error in kd-tree.