Bug 1374047 - Keep WebSocketImpl alive before calling DisconnectInternal. r=smaug, a=jcristau
--- 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();