Fix the bug that uses an iterator after it is erased.