1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:37:44 +00:00

LibWebSocket: Use deferred_invoke() when discarding a connection

We don't want to destroy the WebSocketImpl while we're still using it
higher up the stack. By using deferred_invoke(), we allow the stack
to unwind before actually destroying any objects.

This fixes an issue with the WebSocket service crashing on immediate
connection failure.
This commit is contained in:
Andreas Kling 2021-09-18 12:56:35 +02:00
parent f82c4c4137
commit 1735d978ed

View file

@ -565,12 +565,14 @@ void WebSocket::fatal_error(WebSocket::Error error)
void WebSocket::discard_connection()
{
VERIFY(m_impl);
m_impl->discard_connection();
m_impl->on_connection_error = nullptr;
m_impl->on_connected = nullptr;
m_impl->on_ready_to_read = nullptr;
m_impl = nullptr;
deferred_invoke([this] {
VERIFY(m_impl);
m_impl->discard_connection();
m_impl->on_connection_error = nullptr;
m_impl->on_connected = nullptr;
m_impl->on_ready_to_read = nullptr;
m_impl = nullptr;
});
}
void WebSocket::notify_open()