From 1735d978ed24493268361136f7d02ff4e013b155 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 18 Sep 2021 12:56:35 +0200 Subject: [PATCH] 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. --- Userland/Libraries/LibWebSocket/WebSocket.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWebSocket/WebSocket.cpp b/Userland/Libraries/LibWebSocket/WebSocket.cpp index 06b74c0fbe..ed7825c0b5 100644 --- a/Userland/Libraries/LibWebSocket/WebSocket.cpp +++ b/Userland/Libraries/LibWebSocket/WebSocket.cpp @@ -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()