Bug 1033121 - Release |mTimer| in nsTimerEvent::Run() instead of ~nsTimerEvent() to avoid race. r=bz, a=sledru
authorJW Wang <jwwang@mozilla.com>
Thu, 10 Jul 2014 11:23:02 -0400
changeset 209139 86f3313577835eea2e1d1aecaffa5355d6807e20
parent 209138 e1b73deedcb4510a03615fc1e364ac912805b938
child 209140 4f934dd2701009dbf1edb77ee769e361d6b3fa4b
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, sledru
bugs1033121
milestone32.0a2
Bug 1033121 - Release |mTimer| in nsTimerEvent::Run() instead of ~nsTimerEvent() to avoid race. r=bz, a=sledru
xpcom/threads/nsTimerImpl.cpp
--- a/xpcom/threads/nsTimerImpl.cpp
+++ b/xpcom/threads/nsTimerImpl.cpp
@@ -704,16 +704,21 @@ nsTimerEvent::Run()
     TimeStamp now = TimeStamp::Now();
     PR_LOG(GetTimerLog(), PR_LOG_DEBUG,
            ("[this=%p] time between PostTimerEvent() and Fire(): %fms\n",
             this, (now - mInitTime).ToMilliseconds()));
   }
 #endif
 
   mTimer->Fire();
+  // Since nsTimerImpl is not thread-safe, we should release |mTimer|
+  // here in the target thread to avoid race condition. Otherwise,
+  // ~nsTimerEvent() which calls nsTimerImpl::Release() could run in the
+  // timer thread and result in race condition.
+  mTimer = nullptr;
 
   return NS_OK;
 }
 
 already_AddRefed<nsTimerImpl>
 nsTimerImpl::PostTimerEvent(already_AddRefed<nsTimerImpl> aTimerRef)
 {
   nsRefPtr<nsTimerImpl> timer(aTimerRef);