Fix invalid iterator use when removing modes in ModuleManager::DoSafeUnload()