explicitly check memory allocations in the _depth_first_iterative