From 9504f194280791e04b468ecb518e175305757c5f Mon Sep 17 00:00:00 2001 From: "ananta@chromium.org" Date: Sat, 15 Nov 2008 03:03:30 +0000 Subject: Fix erase method usage on STL containers in Chrome. Invoking erase on the iterator renders it invalid. We were continuing to use this iterator. R=darin Review URL: http://codereview.chromium.org/10925 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5531 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/importer/firefox_importer_utils.cc | 9 +++++++-- chrome/browser/resource_dispatcher_host.cc | 2 +- chrome/browser/resource_dispatcher_host.h | 5 ++++- 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'chrome/browser') diff --git a/chrome/browser/importer/firefox_importer_utils.cc b/chrome/browser/importer/firefox_importer_utils.cc index 61b4b5b..719ebcc 100644 --- a/chrome/browser/importer/firefox_importer_utils.cc +++ b/chrome/browser/importer/firefox_importer_utils.cc @@ -195,11 +195,13 @@ void ParseSearchEnginesFromXMLFiles(const std::vector& xml_files, std::map search_engine_for_url; std::string content; + bool need_to_increment_iter; // The first XML file represents the default search engine in Firefox 3, so we // need to keep it on top of the list. TemplateURL* default_turl = NULL; for (std::vector::const_iterator iter = xml_files.begin(); - iter != xml_files.end(); ++iter) { + iter != xml_files.end();) { + need_to_increment_iter = true; file_util::ReadFileToString(*iter, &content); TemplateURL* template_url = new TemplateURL(); FirefoxURLParameterFilter param_filter; @@ -216,7 +218,8 @@ void ParseSearchEnginesFromXMLFiles(const std::vector& xml_files, // returns a vector with first Firefox default search engines and then // the user's ones. We want to give priority to the user ones. delete iter->second; - search_engine_for_url.erase(iter); + iter = search_engine_for_url.erase(iter); + need_to_increment_iter = false; } // Give this a keyword to facilitate tab-to-search, if possible. template_url->set_keyword(TemplateURLModel::GenerateKeyword(GURL(url), @@ -229,6 +232,8 @@ void ParseSearchEnginesFromXMLFiles(const std::vector& xml_files, delete template_url; } content.clear(); + if (need_to_increment_iter) + ++iter; } // Put the results in the |search_engines| vector. diff --git a/chrome/browser/resource_dispatcher_host.cc b/chrome/browser/resource_dispatcher_host.cc index fdaadc3..6f1aba3 100644 --- a/chrome/browser/resource_dispatcher_host.cc +++ b/chrome/browser/resource_dispatcher_host.cc @@ -1923,7 +1923,7 @@ void ResourceDispatcherHost::RemovePendingRequest(int render_process_host_id, } void ResourceDispatcherHost::RemovePendingRequest( - PendingRequestList::iterator& iter) { + const PendingRequestList::iterator& iter) { // Notify the login handler that this request object is going away. ExtraRequestInfo* info = ExtraInfoForRequest(iter->second); if (info && info->login_handler) diff --git a/chrome/browser/resource_dispatcher_host.h b/chrome/browser/resource_dispatcher_host.h index 3207965..fc21c7e 100644 --- a/chrome/browser/resource_dispatcher_host.h +++ b/chrome/browser/resource_dispatcher_host.h @@ -414,7 +414,10 @@ class ResourceDispatcherHost : public URLRequest::Delegate { const std::string& content_disposition); void RemovePendingRequest(int render_process_host_id, int request_id); - void RemovePendingRequest(PendingRequestList::iterator& iter); + // Deletes the pending request identified by the iterator passed in. + // This function will invalidate the iterator passed in. Callers should + // not rely on this iterator being valid on return. + void RemovePendingRequest(const PendingRequestList::iterator& iter); // Notify our observers that we started receiving a response for a request. void NotifyResponseStarted(URLRequest* request, int render_process_host_id); -- cgit v1.1