fix a segfault caused by stack overflow in handle_stageout