From ec36c97b3f6a5922dbf124c31065a1b067f500ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Tue, 30 Nov 2021 18:16:43 +0100 Subject: [PATCH] Fix win32_spawn leaking dev_null fd in the parent process --- CHANGES | 6 ++++++ src/unix/lwt_process.ml | 14 ++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 2a08836ac9..0932632c27 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +===== dev ===== + +====== Fixes ====== + + * Fix win32_spawn leaking dev_null fd in the parent process. (#906, Antonin Décimo) + ===== 5.5.0 ===== ====== Deprecations ====== diff --git a/src/unix/lwt_process.ml b/src/unix/lwt_process.ml index cbd2a6e285..f6534938da 100644 --- a/src/unix/lwt_process.ml +++ b/src/unix/lwt_process.ml @@ -91,15 +91,21 @@ let win32_spawn (if prog = "" then None else Some prog) cmdline env cwd (stdin_fd, stdout_fd, stderr_fd) in - let close = function + let close fd fd' = + match fd with | `FD_move fd -> Unix.close fd + | `Dev_null -> + begin match fd' with + | Some fd' -> Unix.close fd' + | None -> assert false + end | _ -> () in - close stdin; - close stdout; - close stderr; + close stdin stdin_fd; + close stdout stdout_fd; + close stderr stderr_fd; proc external win32_wait_job : Unix.file_descr -> int Lwt_unix.job =