Fix a bug in the er tree clean-up process

See discussion in #1520. It's not necessary to walk the er tree in order to clean up the memory since it's possible to cleanup the regions in the stack just by iterating over the er_stack vector instead of walking the tree structure. This turns out to be safer because the tree structure of those regions may have been modified previously in er_save function.