Bug 1182515 - WebSocketChannel leaked when WebSocketChannel::AsyncOpen fails, r=mcmanus

This commit is contained in:
Michal Novotny 2015-08-31 23:34:59 +02:00
parent d5b39c2424
commit b630760890

View File

@ -3265,6 +3265,26 @@ WebSocketChannel::AsyncOpen(nsIURI *aURI,
// nsIChannelEventSink in this object in order to deal with redirects
localChannel->SetNotificationCallbacks(this);
class MOZ_STACK_CLASS CleanUpOnFailure
{
public:
explicit CleanUpOnFailure(WebSocketChannel* aWebSocketChannel)
: mWebSocketChannel(aWebSocketChannel)
{}
~CleanUpOnFailure()
{
if (!mWebSocketChannel->mWasOpened) {
mWebSocketChannel->mChannel = nullptr;
mWebSocketChannel->mHttpChannel = nullptr;
}
}
WebSocketChannel *mWebSocketChannel;
};
CleanUpOnFailure cuof(this);
mChannel = do_QueryInterface(localChannel, &rv);
NS_ENSURE_SUCCESS(rv, rv);