fix(Process/Win): correct handling of PROCESS_CLOSE_STD* flags#5192
Merged
fix(Process/Win): correct handling of PROCESS_CLOSE_STD* flags#5192
Conversation
26a6ccb to
726fb0c
Compare
726fb0c to
8df50df
Compare
8df50df to
b61230d
Compare
aleks-f
approved these changes
Feb 9, 2026
Contributor
There was a problem hiding this comment.
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(notGetStdHandle()results) whenPROCESS_CLOSE_STD*flags are set. - Add a regression test that launches a child with
PROCESS_CLOSE_STDOUT/PROCESS_CLOSE_STDERRand verifies the parent can still write tostd::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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #5191.
PROCESS_CLOSE_STDIN,PROCESS_CLOSE_STDOUT, andPROCESS_CLOSE_STDERRoptions inProcess_WIN32U.cppincorrectly closed the parent process's standard handles (viaGetStdHandle()) instead of closing the duplicated handles instartupInfothat 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::coutorstd::cerr).The fix closes the already-duplicated
startupInfo.hStdInput/hStdOutput/hStdErrorhandles 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 afterfork().Test plan
PROCESS_CLOSE_STDOUT | PROCESS_CLOSE_STDERRno longer crashes the parent