Skip to content

fix(Process/Win): correct handling of PROCESS_CLOSE_STD* flags#5192

Merged
matejk merged 3 commits intomainfrom
5191-process-close-std-handles
Feb 9, 2026
Merged

fix(Process/Win): correct handling of PROCESS_CLOSE_STD* flags#5192
matejk merged 3 commits intomainfrom
5191-process-close-std-handles

Conversation

@matejk
Copy link
Copy Markdown
Contributor

@matejk matejk commented Feb 8, 2026

Summary

Fixes #5191.

PROCESS_CLOSE_STDIN, PROCESS_CLOSE_STDOUT, and PROCESS_CLOSE_STDERR options in Process_WIN32U.cpp incorrectly closed the parent process's standard handles (via GetStdHandle()) instead of closing the duplicated handles in startupInfo that are about to be inherited by the child process.

This caused the parent process to lose its own stdin/stdout/stderr handles, leading to crashes on subsequent I/O (e.g., writing to std::cout or std::cerr).

The fix closes the already-duplicated startupInfo.hStdInput/hStdOutput/hStdError handles instead — preventing the child from inheriting them without affecting the parent. This is consistent with the POSIX implementation where these closes happen inside the child process after fork().

Test plan

  • Verified with test suite on Windows — launching child processes with PROCESS_CLOSE_STDOUT | PROCESS_CLOSE_STDERR no longer crashes the parent
  • No impact on Linux/macOS (POSIX code paths are unaffected)

@matejk matejk requested a review from aleks-f February 8, 2026 18:31
@matejk matejk force-pushed the 5191-process-close-std-handles branch from 26a6ccb to 726fb0c Compare February 8, 2026 20:40
@matejk matejk force-pushed the 5191-process-close-std-handles branch from 726fb0c to 8df50df Compare February 9, 2026 09:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect handling of PROCESS_CLOSE_STDIN/STDOUT/STDERR on Windows by ensuring only the child’s duplicated standard handles are closed (in STARTUPINFO), preventing accidental closure of the parent process’s std handles and subsequent parent I/O failures.

Changes:

  • Update Win32 process launch implementation to close startupInfo.hStdInput/hStdOutput/hStdError (not GetStdHandle() results) when PROCESS_CLOSE_STD* flags are set.
  • Add a regression test that launches a child with PROCESS_CLOSE_STDOUT/PROCESS_CLOSE_STDERR and verifies the parent can still write to std::cout/std::cerr.
  • Register the new test in the Process test suite.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
Foundation/src/Process_WIN32U.cpp Fixes handle-closing logic to target duplicated child handles rather than the parent’s standard handles.
Foundation/testsuite/src/ProcessTest.cpp Adds regression coverage for close-stdio flags, ensuring parent std streams remain usable after launch.
Foundation/testsuite/src/ProcessTest.h Declares the new testLaunchCloseHandles() test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@matejk matejk merged commit 5e17646 into main Feb 9, 2026
94 of 97 checks passed
@matejk matejk deleted the 5191-process-close-std-handles branch February 9, 2026 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Process_WIN32U: PROCESS_CLOSE_STD* flags close parent's handles instead of child's

3 participants