Make a copy before enumerating profiles because the list might change underneath.

If a profile is created/removed as a result of the call to AddProfile inside it
will crash because the iterator is invalidated.

BUG=319676
TEST=On Mac as described in the bug.

Review URL: https://codereview.chromium.org/65643006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235736 0039d316-1c4b-4281-b951-d872f2087c98
parent 30a9071a
...@@ -397,19 +397,19 @@ std::vector<Profile*> ProfileManager::GetLastOpenedProfiles( ...@@ -397,19 +397,19 @@ std::vector<Profile*> ProfileManager::GetLastOpenedProfiles(
DCHECK(local_state); DCHECK(local_state);
std::vector<Profile*> to_return; std::vector<Profile*> to_return;
if (local_state->HasPrefPath(prefs::kProfilesLastActive)) { if (local_state->HasPrefPath(prefs::kProfilesLastActive) &&
const ListValue* profile_list = local_state->GetList(prefs::kProfilesLastActive)) {
local_state->GetList(prefs::kProfilesLastActive); // Make a copy because the list might change in the calls to GetProfile.
if (profile_list) { scoped_ptr<base::ListValue> profile_list(
ListValue::const_iterator it; local_state->GetList(prefs::kProfilesLastActive)->DeepCopy());
std::string profile; base::ListValue::const_iterator it;
for (it = profile_list->begin(); it != profile_list->end(); ++it) { std::string profile;
if (!(*it)->GetAsString(&profile) || profile.empty()) { for (it = profile_list->begin(); it != profile_list->end(); ++it) {
LOG(WARNING) << "Invalid entry in " << prefs::kProfilesLastActive; if (!(*it)->GetAsString(&profile) || profile.empty()) {
continue; LOG(WARNING) << "Invalid entry in " << prefs::kProfilesLastActive;
} continue;
to_return.push_back(GetProfile(user_data_dir.AppendASCII(profile)));
} }
to_return.push_back(GetProfile(user_data_dir.AppendASCII(profile)));
} }
} }
return to_return; return to_return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment