diff --git a/crates/uv-trampoline/src/bounce.rs b/crates/uv-trampoline/src/bounce.rs index c8a71994ef43..22c59340a0bf 100644 --- a/crates/uv-trampoline/src/bounce.rs +++ b/crates/uv-trampoline/src/bounce.rs @@ -344,17 +344,23 @@ fn close_handles(si: &STARTUPINFOA) { if si.cbReserved2 == 0 || si.lpReserved2.is_null() { return; } + let crt_magic = si.lpReserved2 as *const u32; let handle_count = unsafe { crt_magic.read_unaligned() } as isize; - let handle_start = unsafe { crt_magic.offset(1 + handle_count) }; - for i in 0..handle_count { - let handle = HANDLE(unsafe { handle_start.offset(i).read_unaligned() as _ }); - // Close all fds inherited from the parent, except for the standard I/O fds. - if !handle.is_invalid() { - unsafe { CloseHandle(handle) }.unwrap_or_else(|_| { - eprintln!("Failed to close child file descriptors at {}", i); - }); + let handle_start = + unsafe { (crt_magic.offset(1) as *const u8).offset(handle_count) as *const HANDLE }; + + // Close all fds inherited from the parent, except for the standard I/O fds (skip first 3). + for i in 3..handle_count { + let handle = unsafe { handle_start.offset(i).read_unaligned() }; + // Ignore invalid handles, as that means this fd was not inherited. + // -2 is a special value (https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle) + if handle.is_invalid() || handle.0 == -2 as _ { + continue; } + unsafe { CloseHandle(handle) }.unwrap_or_else(|_| { + eprintln!("Failed to close child file descriptors at {}", i); + }); } } diff --git a/crates/uv-trampoline/trampolines/uv-trampoline-aarch64-console.exe b/crates/uv-trampoline/trampolines/uv-trampoline-aarch64-console.exe index 0a4e2323afc9..5b6ea9cab831 100755 Binary files a/crates/uv-trampoline/trampolines/uv-trampoline-aarch64-console.exe and b/crates/uv-trampoline/trampolines/uv-trampoline-aarch64-console.exe differ diff --git a/crates/uv-trampoline/trampolines/uv-trampoline-aarch64-gui.exe b/crates/uv-trampoline/trampolines/uv-trampoline-aarch64-gui.exe index ab26a5dba42a..1f6524111b1e 100755 Binary files a/crates/uv-trampoline/trampolines/uv-trampoline-aarch64-gui.exe and b/crates/uv-trampoline/trampolines/uv-trampoline-aarch64-gui.exe differ diff --git a/crates/uv-trampoline/trampolines/uv-trampoline-i686-console.exe b/crates/uv-trampoline/trampolines/uv-trampoline-i686-console.exe index d0c20ac46706..3f0bed6a18a4 100755 Binary files a/crates/uv-trampoline/trampolines/uv-trampoline-i686-console.exe and b/crates/uv-trampoline/trampolines/uv-trampoline-i686-console.exe differ diff --git a/crates/uv-trampoline/trampolines/uv-trampoline-i686-gui.exe b/crates/uv-trampoline/trampolines/uv-trampoline-i686-gui.exe index 2250d5a5e401..936aedb5e003 100755 Binary files a/crates/uv-trampoline/trampolines/uv-trampoline-i686-gui.exe and b/crates/uv-trampoline/trampolines/uv-trampoline-i686-gui.exe differ diff --git a/crates/uv-trampoline/trampolines/uv-trampoline-x86_64-console.exe b/crates/uv-trampoline/trampolines/uv-trampoline-x86_64-console.exe index ac528ac78ba7..8ba2f2b5acd0 100755 Binary files a/crates/uv-trampoline/trampolines/uv-trampoline-x86_64-console.exe and b/crates/uv-trampoline/trampolines/uv-trampoline-x86_64-console.exe differ diff --git a/crates/uv-trampoline/trampolines/uv-trampoline-x86_64-gui.exe b/crates/uv-trampoline/trampolines/uv-trampoline-x86_64-gui.exe index 1d9c5ab50e46..9f503fe512c9 100755 Binary files a/crates/uv-trampoline/trampolines/uv-trampoline-x86_64-gui.exe and b/crates/uv-trampoline/trampolines/uv-trampoline-x86_64-gui.exe differ