Bug 1177501 - Hold a strong ref to mThread. r=jya
authorBobby Holley <bobbyholley@gmail.com>
Thu, 25 Jun 2015 13:20:04 -0700
changeset 250395 10ac7b53802a130d1c225d4c43033dca152edaab
parent 250394 28e6664ad1a16463932d397aaac7f3fbc6bde73b
child 250396 40a894ed5740d3e0aa8e52c8a1053598d53f4cb7
push id61547
push userbobbyholley@gmail.com
push dateSat, 27 Jun 2015 08:19:49 +0000
treeherdermozilla-inbound@9fb9dbd7a0dd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1177501
milestone41.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 1177501 - Hold a strong ref to mThread. r=jya
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());