microsoft/terminal

ClosePseudoConsole does not close the process handle to conhost

asmichi opened this issue · 3 comments

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)

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).

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)

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.