Bug 1436972 - Hold ref counted AudioSession for proper lifetime when re-initializing. r=jimm, a=jcristau
authorDavid Parks <dparks@mozilla.com>
Wed, 21 Mar 2018 19:37:44 -0700
changeset 462994 4c10eb56d4607cd77b4846c73f00d992627ac0f0
parent 462993 989d666031dbef2dfdbe575aad0edda22275a095
child 462995 14ea71e3100ee7c5e3f1f8abc46ce14211e6457f
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, jcristau
bugs1436972
milestone60.0
Bug 1436972 - Hold ref counted AudioSession for proper lifetime when re-initializing. r=jimm, a=jcristau The scope of the kungFuDeathGrip is supposed to include the call to Start() (as suggested by the comment).
widget/windows/AudioSession.cpp
--- a/widget/windows/AudioSession.cpp
+++ b/widget/windows/AudioSession.cpp
@@ -443,27 +443,28 @@ AudioSession::OnSessionDisconnected(Audi
                       this, &AudioSession::OnSessionDisconnectedInternal);
   NS_DispatchToMainThread(runnable);
   return S_OK;
 }
 
 nsresult
 AudioSession::OnSessionDisconnectedInternal()
 {
+  // When successful, UnregisterAudioSessionNotification will decrement the
+  // refcount of 'this'.  Start will re-increment it.  In the interim,
+  // we'll need to reference ourselves.
+  RefPtr<AudioSession> kungFuDeathGrip(this);
+
   {
     // We need to release the mutex before we call Start().
     MutexAutoLock lock(mMutex);
 
     if (!mAudioSessionControl)
       return NS_OK;
 
-    // When successful, UnregisterAudioSessionNotification will decrement the
-    // refcount of 'this'.  Start will re-increment it.  In the interim,
-    // we'll need to reference ourselves.
-    RefPtr<AudioSession> kungFuDeathGrip(this);
     mAudioSessionControl->UnregisterAudioSessionNotification(this);
     mAudioSessionControl = nullptr;
   }
 
   mState = AUDIO_SESSION_DISCONNECTED;
   CoUninitialize();
   Start(); // If it fails there's not much we can do.
   return NS_OK;