fix use after free related to orphans.