From 52a7282c6429aedd3b214829fb2ec71fc122f8d4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 8 Oct 2022 11:01:59 +0200 Subject: [PATCH] Ladybird: Close the other side's file descriptors after forking When spawning a WebContent process, we have to close the file descriptors belonging to the "other side" in both processes, or they will not get naturally "cleaned up" when one of the processes exits. Fixes #93 --- Ladybird/WebContentView.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index 071c4f7229..04f705c9bf 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -563,6 +563,9 @@ void WebContentView::create_client() auto child_pid = fork(); if (!child_pid) { + MUST(Core::System::close(ui_fd_passing_fd)); + MUST(Core::System::close(ui_fd)); + auto takeover_string = String::formatted("x:{}", wc_fd); MUST(Core::System::setenv("SOCKET_TAKEOVER"sv, takeover_string, true)); @@ -577,6 +580,9 @@ void WebContentView::create_client() VERIFY_NOT_REACHED(); } + MUST(Core::System::close(wc_fd_passing_fd)); + MUST(Core::System::close(wc_fd)); + auto socket = MUST(Core::Stream::LocalSocket::adopt_fd(ui_fd)); MUST(socket->set_blocking(true));