Truly independent web browser
LibCore: Keep a LocalServer alive through its accept callbacks
Shannon Booth9d83adafb81b
diff --git a/Libraries/LibCore/LocalServer.cpp b/Libraries/LibCore/LocalServer.cppindex 170681e70bb..dfa75660cb5 100644--- a/Libraries/LibCore/LocalServer.cpp+++ b/Libraries/LibCore/LocalServer.cpp@@ -42,6 +42,7 @@ void LocalServer::setup_notifier(){m_notifier = Notifier::construct(m_fd, Notifier::Type::Read);m_notifier->on_activation = [this] {+ auto protector = NonnullRefPtr { *this };if (on_accept) {auto maybe_client_socket = accept();if (maybe_client_socket.is_error()) {diff --git a/Libraries/LibCore/LocalServerWindows.cpp b/Libraries/LibCore/LocalServerWindows.cppindex cce48e67b96..c9935644b79 100644--- a/Libraries/LibCore/LocalServerWindows.cpp+++ b/Libraries/LibCore/LocalServerWindows.cpp@@ -38,6 +38,7 @@ void LocalServer::setup_notifier(){m_notifier = Notifier::construct(m_fd, Notifier::Type::Read);m_notifier->on_activation = [this] {+ auto protector = NonnullRefPtr { *this };if (on_accept) {auto maybe_client_socket = accept();if (maybe_client_socket.is_error()) {diff --git a/Tests/LibCore/TestLibCoreStream.cpp b/Tests/LibCore/TestLibCoreStream.cppindex 2a1405104e9..ada74901fdd 100644--- a/Tests/LibCore/TestLibCoreStream.cpp+++ b/Tests/LibCore/TestLibCoreStream.cpp@@ -349,6 +349,19 @@ TEST_CASE(udp_socket_read_write)// LocalSocket tests+TEST_CASE(local_server_can_lose_its_owner_during_accept)+{+ Core::EventLoop event_loop;+ auto socket_path = temporary_path("accept-drops-server"sv);+ RefPtr<Core::LocalServer> server = Core::LocalServer::construct();+ EXPECT(server->listen(socket_path));+ server->on_accept = [&](auto) { server = nullptr; };++ auto client = TRY_OR_FAIL(Core::LocalSocket::connect(socket_path));+ event_loop.spin_until([&] { return !server; });+ TRY_OR_FAIL(FileSystem::remove(socket_path, FileSystem::RecursionMode::Disallowed));+}+TEST_CASE(local_socket_read){Core::EventLoop event_loop;