Bug 1177501 - Hold a strong ref to mThread. r=jya, a=lmandel
authorBobby Holley <bobbyholley@gmail.com>
Thu, 25 Jun 2015 13:20:04 -0700
changeset 275364 05d720b741cf160f9c5358b12dd90f1c74c6777b
parent 275363 2a4f3dedeccfd1fbd6c6e774d77fdcc55c19344e
child 275365 f98edcdf3c24d1e7d542a26f3d870b29d593fa2f
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya, lmandel
bugs1177501
milestone40.0
Bug 1177501 - Hold a strong ref to mThread. r=jya, a=lmandel
dom/media/MediaTimer.cpp
--- a/dom/media/MediaTimer.cpp
+++ b/dom/media/MediaTimer.cpp
@@ -34,17 +34,21 @@ MediaTimer::MediaTimer()
   mThread = threadPool.get();
   mTimer->SetTarget(mThread);
 }
 
 void
 MediaTimer::DispatchDestroy()
 {
   nsCOMPtr<nsIRunnable> task = NS_NewNonOwningRunnableMethod(this, &MediaTimer::Destroy);
-  nsresult rv = mThread->Dispatch(task, NS_DISPATCH_NORMAL);
+  // Hold a strong reference to the thread so that it doesn't get deleted in
+  // Destroy(), which may run completely before the stack if Dispatch() begins
+  // to unwind.
+  nsCOMPtr<nsIEventTarget> thread = mThread;
+  nsresult rv = thread->Dispatch(task, NS_DISPATCH_NORMAL);
   MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
   (void) rv;
 }
 
 void
 MediaTimer::Destroy()
 {
   MOZ_ASSERT(OnMediaTimerThread());