Bug 1307858 - Use a copy of the list of observers to broadcast. r=froydnj
authorDylan Roeh <droeh@mozilla.com>
Fri, 16 Dec 2016 14:49:25 -0600
changeset 452478 fc1d94a3195dead36a75a5f203fa90b19ecd551e
parent 452477 11873cde7a5992d3b721abc17b35ff8f28dae0ae
child 452479 664ed8d2eaffe16894095bbe294dcb80a3774953
push id39415
push usermozilla@noorenberghe.ca
push dateWed, 21 Dec 2016 20:49:14 +0000
reviewersfroydnj
bugs1307858
milestone53.0a1
Bug 1307858 - Use a copy of the list of observers to broadcast. r=froydnj
xpcom/glue/Observer.h
--- a/xpcom/glue/Observer.h
+++ b/xpcom/glue/Observer.h
@@ -62,19 +62,20 @@ public:
 
   uint32_t Length()
   {
     return mObservers.Length();
   }
 
   void Broadcast(const T& aParam)
   {
-    uint32_t size = mObservers.Length();
+    nsTArray<Observer<T>*> observersCopy(mObservers);
+    uint32_t size = observersCopy.Length();
     for (uint32_t i = 0; i < size; ++i) {
-      mObservers[i]->Notify(aParam);
+      observersCopy[i]->Notify(aParam);
     }
   }
 
 protected:
   nsTArray<Observer<T>*> mObservers;
 };
 
 } // namespace mozilla