Bug 1374047 - Keep WebSocketImpl alive before calling DisconnectInternal. r=smaug, a=jcristau
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 12 Jul 2017 17:12:40 -0400
changeset 411922 a9897f5c997e9ec158ea305940db4a75e8ca5202
parent 411921 aae715e5060bcc675cb09113b3b1198bb0c94694
child 411923 59ea27873e7bd98491669e3c815879777542dd34
push id7503
push userryanvm@gmail.com
push dateWed, 12 Jul 2017 21:21:02 +0000
treeherdermozilla-beta@a98632e47afd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, jcristau
bugs1374047
milestone55.0
Bug 1374047 - Keep WebSocketImpl alive before calling DisconnectInternal. r=smaug, a=jcristau
dom/base/WebSocket.cpp
--- a/dom/base/WebSocket.cpp
+++ b/dom/base/WebSocket.cpp
@@ -610,16 +610,20 @@ void
 WebSocketImpl::Disconnect()
 {
   if (mDisconnectingOrDisconnected) {
     return;
   }
 
   AssertIsOnTargetThread();
 
+  // DontKeepAliveAnyMore() and DisconnectInternal() can release the object. So
+  // hold a reference to this until the end of the method.
+  RefPtr<WebSocketImpl> kungfuDeathGrip = this;
+
   // Disconnect can be called from some control event (such as Notify() of
   // WorkerHolder). This will be schedulated before any other sync/async
   // runnable. In order to prevent some double Disconnect() calls, we use this
   // boolean.
   mDisconnectingOrDisconnected = true;
 
   // DisconnectInternal touches observers and nsILoadGroup and it must run on
   // the main thread.
@@ -631,20 +635,16 @@ WebSocketImpl::Disconnect()
       new DisconnectInternalRunnable(this);
     ErrorResult rv;
     runnable->Dispatch(Killing, rv);
     // XXXbz this seems totally broken.  We should be propagating this out, but
     // where to, exactly?
     rv.SuppressException();
   }
 
-  // DontKeepAliveAnyMore() can release the object. So hold a reference to this
-  // until the end of the method.
-  RefPtr<WebSocketImpl> kungfuDeathGrip = this;
-
   NS_ReleaseOnMainThread(mChannel.forget());
   NS_ReleaseOnMainThread(mService.forget());
 
   mWebSocket->DontKeepAliveAnyMore();
   mWebSocket->mImpl = nullptr;
 
   if (mWorkerPrivate && mWorkerHolder) {
     UnregisterWorkerHolder();