Bug 1307858 - Use a copy of the list of observers to broadcast. r=froydnj, a=lizzard
authorDylan Roeh <droeh@mozilla.com>
Fri, 16 Dec 2016 14:49:25 -0600
changeset 353279 0eeed34e22e43b12834f6619689827896b41a50c
parent 353278 d08c9540a13c3c183f592c7378688b14d8101d87
child 353280 fe80ac73a1121b8ba7a6c7040a1f25d19b030739
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, lizzard
bugs1307858
milestone52.0a2
Bug 1307858 - Use a copy of the list of observers to broadcast. r=froydnj, a=lizzard
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