Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Unified Diff: chrome/utility/chrome_content_utility_client.cc

Issue 1951213002: Avoid incrementing an invalid iterator in the utility process client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comment. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/utility/chrome_content_utility_client.cc
diff --git a/chrome/utility/chrome_content_utility_client.cc b/chrome/utility/chrome_content_utility_client.cc
index 8bd49b41ab339f9c7cc56db93da6ead3a4bcff82..7a6b21a833f6f1259c1216dff18f4194339f3420 100644
--- a/chrome/utility/chrome_content_utility_client.cc
+++ b/chrome/utility/chrome_content_utility_client.cc
@@ -175,12 +175,20 @@ bool ChromeContentUtilityClient::OnMessageReceived(
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
- for (Handlers::iterator it = handlers_.begin();
- !handled && it != handlers_.end(); ++it) {
- handled = (*it)->OnMessageReceived(message);
+ if (handled)
+ return true;
+
+ for (const auto& handler : handlers_) {
+ // At least one of the utility process handlers adds a new handler to
+ // |handlers_| when it handles a message. This causes any iterator over
+ // |handlers_| to become invalid. Therefore, it is necessary to break the
+ // loop at this point instead of evaluating it as a loop condition (if the
+ // for loop was using iterators explicitly, as originally done).
+ if (handler->OnMessageReceived(message))
+ return true;
}
- return handled;
+ return false;
}
void ChromeContentUtilityClient::RegisterMojoServices(
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698