Bug 1042561 - Iterate a copy of mSearches in StartSearch() so that an observer can't modify the array we're iterating r=mak
authorTim Taubert <ttaubert@mozilla.com>
Mon, 23 Mar 2015 08:33:53 +0100
changeset 264160 63f55bf75ba9226c1c4cb9589b1b59c019b3f3c5
parent 264159 8b4af50a0cb806f76c804c0e662e22a0d99d9d4d
child 264161 66e17a44a01cf30f248cb725ca156ac6c6c84936
push id4718
push userraliiev@mozilla.com
push dateMon, 11 May 2015 18:39:53 +0000
treeherdermozilla-beta@c20c4ef55f08 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1042561
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1042561 - Iterate a copy of mSearches in StartSearch() so that an observer can't modify the array we're iterating r=mak
toolkit/components/autocomplete/nsAutoCompleteController.cpp
--- a/toolkit/components/autocomplete/nsAutoCompleteController.cpp
+++ b/toolkit/components/autocomplete/nsAutoCompleteController.cpp
@@ -1105,18 +1105,23 @@ nsAutoCompleteController::BeforeSearches
 }
 
 nsresult
 nsAutoCompleteController::StartSearch(uint16_t aSearchType)
 {
   NS_ENSURE_STATE(mInput);
   nsCOMPtr<nsIAutoCompleteInput> input = mInput;
 
-  for (uint32_t i = 0; i < mSearches.Length(); ++i) {
-    nsCOMPtr<nsIAutoCompleteSearch> search = mSearches[i];
+  // Iterate a copy of |mSearches| so that we don't run into trouble if the
+  // array is mutated while we're still in the loop. An nsIAutoCompleteSearch
+  // implementation could synchronously start a new search when StartSearch()
+  // is called and that would lead to assertions down the way.
+  nsCOMArray<nsIAutoCompleteSearch> searchesCopy(mSearches);
+  for (uint32_t i = 0; i < searchesCopy.Length(); ++i) {
+    nsCOMPtr<nsIAutoCompleteSearch> search = searchesCopy[i];
 
     // Filter on search type.  Not all the searches implement this interface,
     // in such a case just consider them delayed.
     uint16_t searchType = nsIAutoCompleteSearchDescriptor::SEARCH_TYPE_DELAYED;
     nsCOMPtr<nsIAutoCompleteSearchDescriptor> searchDesc =
       do_QueryInterface(search);
     if (searchDesc)
       searchDesc->GetSearchType(&searchType);