diff options
author | 2022-08-18 23:41:33 -0700 | |
---|---|---|
committer | 2022-08-18 23:41:33 -0700 | |
commit | bdf733973c72b8e156cd1cf1c6c8a8b4649fedbe (patch) | |
tree | 990cf3bafe817aec5ed5e4903a53eed524d25bdf | |
parent | 0f45386673fbf4f33b6e61b17ea49b69697ec79a (diff) | |
download | bun-bdf733973c72b8e156cd1cf1c6c8a8b4649fedbe.tar.gz bun-bdf733973c72b8e156cd1cf1c6c8a8b4649fedbe.tar.zst bun-bdf733973c72b8e156cd1cf1c6c8a8b4649fedbe.zip |
Fix memory leak in `WebSocket`
-rw-r--r-- | src/bun.js/bindings/webcore/WebSocket.cpp | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/src/bun.js/bindings/webcore/WebSocket.cpp b/src/bun.js/bindings/webcore/WebSocket.cpp index 9f8bf3ed6..004b907b5 100644 --- a/src/bun.js/bindings/webcore/WebSocket.cpp +++ b/src/bun.js/bindings/webcore/WebSocket.cpp @@ -831,18 +831,9 @@ void WebSocket::didReceiveMessageError(WTF::StringImpl::StaticStringImpl* reason m_state = CLOSED; if (auto* context = scriptExecutionContext()) { this->m_pendingActivityCount++; - - context->postTask([this, reason, protectedThis = Ref { *this }](ScriptExecutionContext& context) { - ASSERT(scriptExecutionContext()); - // if (UNLIKELY(InspectorInstrumentation::hasFrontends())) { - // if (auto* inspector = m_channel->channelInspector()) - // inspector->didReceiveWebSocketFrameError(reason); - // } - - // FIXME: As per https://html.spec.whatwg.org/multipage/web-sockets.html#feedback-from-the-protocol:concept-websocket-closed, we should synchronously fire a close event. - dispatchEvent(CloseEvent::create(false, 0, WTF::String(reason))); - protectedThis->m_pendingActivityCount--; - }); + // https://html.spec.whatwg.org/multipage/web-sockets.html#feedback-from-the-protocol:concept-websocket-closed, we should synchronously fire a close event. + dispatchEvent(CloseEvent::create(false, 0, WTF::String(reason))); + this->m_pendingActivityCount--; } } @@ -894,7 +885,7 @@ void WebSocket::didClose(unsigned unhandledBufferedAmount, unsigned short code, context->postTask([this, code, wasClean, reason, protectedThis = Ref { *this }](ScriptExecutionContext& context) { ASSERT(scriptExecutionContext()); protectedThis->dispatchEvent(CloseEvent::create(wasClean, code, reason)); - protectedThis->m_pendingActivityCount++; + protectedThis->m_pendingActivityCount--; }); } |