ClosePseudoConsole does not close the process handle to conhost #22267

Closed
opened 2026-01-31 08:08:21 +00:00 by claunia · 3 comments
Owner

Originally created by @asmichi on GitHub (Sep 11, 2024).

Windows Terminal version

N/A

Windows build number

10.0.22631.4037 (Windows 11 Pro, 23H2)

Other Software

(None, just Kernel32)

Steps to reproduce

Run the EchoCon sample and observe its handles before/after the ClosePseudoConsole call.

  • Add a breakpoint at ClosePseudoConsole(hPC)
  • Start debugging
  • Run handle.exe -p EchoCon.exe -a | findstr Process when the program breaks at ClosePseudoConsole(hPC)
  • Step over
  • Run handle.exe -p EchoCon.exe -a | findstr Process

Expected Behavior

ClosePseudoConsole closes the handle to conhost.exe.

Actual Behavior

ClosePseudoConsole does not close the handle to conhost.exe (leaks the handle).

This looks like a Kernel32 version of #8706.

D:\>REM break just before ClosePseudoConsole(hPC)

D:\>handle -p EchoCon.exe -a | findstr Process
   E0: Process       conhost.exe(34388)

D:\>REM step over ClosePseudoConsole(hPC)

D:\>handle -p EchoCon.exe -a | findstr Process
   E0: Process       <Nonexistent process>(34388)
Originally created by @asmichi on GitHub (Sep 11, 2024). ### Windows Terminal version N/A ### Windows build number 10.0.22631.4037 (Windows 11 Pro, 23H2) ### Other Software (None, just Kernel32) ### Steps to reproduce Run the `EchoCon` sample and observe its handles before/after the `ClosePseudoConsole` call. - Add a breakpoint at `ClosePseudoConsole(hPC)` - Start debugging - Run `handle.exe -p EchoCon.exe -a | findstr Process` when the program breaks at `ClosePseudoConsole(hPC)` - Step over - Run `handle.exe -p EchoCon.exe -a | findstr Process` ### Expected Behavior `ClosePseudoConsole` closes the handle to conhost.exe. ### Actual Behavior `ClosePseudoConsole` does not close the handle to conhost.exe (leaks the handle). This looks like a Kernel32 version of #8706. ``` D:\>REM break just before ClosePseudoConsole(hPC) D:\>handle -p EchoCon.exe -a | findstr Process E0: Process conhost.exe(34388) D:\>REM step over ClosePseudoConsole(hPC) D:\>handle -p EchoCon.exe -a | findstr Process E0: Process <Nonexistent process>(34388) ```
Author
Owner

@lhecker commented on GitHub (Sep 11, 2024):

I checked the corresponding branch internally and it doesn't include the CloseHandle fix. The good news is that 24h2 doesn't have this issue (its ClosePseudoConsole implementation is way simpler and more robust).

@lhecker commented on GitHub (Sep 11, 2024): I checked the corresponding branch internally and it doesn't include the `CloseHandle` fix. The good news is that 24h2 doesn't have this issue (its `ClosePseudoConsole` implementation is way simpler and more robust).
Author
Owner

@zadjii-msft commented on GitHub (Sep 12, 2024):

We can probably close this as fix-checked-in, right? I'm not sure we can backport that...

(if you want to backport it, go for it)

@zadjii-msft commented on GitHub (Sep 12, 2024): We can probably close this as fix-checked-in, right? I'm not sure we can backport that... (if you want to backport it, go for it)
Author
Owner

@asmichi commented on GitHub (Sep 14, 2024):

Thank you! I'm glad to hear this is already fixed in the insider build. I have confirmed the fix with 10.0.26120.1542 (Dev Channel).

If backporting is not planned, please feel free to close this as fixed.

@asmichi commented on GitHub (Sep 14, 2024): Thank you! I'm glad to hear this is already fixed in the insider build. I have confirmed the fix with 10.0.26120.1542 (Dev Channel). If backporting is not planned, please feel free to close this as fixed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#22267