ConPTY function CreatePseudoConsole() randomly crashing and throwing a heap corruption exception #19664

Closed
opened 2026-01-31 06:50:08 +00:00 by claunia · 4 comments
Owner

Originally created by @rodrigodevpub on GitHub (Apr 8, 2023).

Windows Terminal version

1.16.10262.0

Windows build number

10.0.22621.1413

Other Software

Only Windows Command Prompt.

Steps to reproduce

Running a slightly modified version of compiled samples/ConPTY/EchoCon (however developed in C, not C++). The creation of Pipes and PseudoConsole is the same as in the example.

Expected Behavior

No response

Actual Behavior

Randomly (<5% of the time), the function CreatePseudoConsole() crashes the program. When that happens, the program terminates with errorlevel -1073740940 (hex 0xc0000374 STATUS_HEAP_CORRUPTION). Tried to handle the exception, but it does not work with __try/__exception. The program works 95% of the time with no different inputs than when the problem happens. Any insights would be really appreciated.

Originally created by @rodrigodevpub on GitHub (Apr 8, 2023). ### Windows Terminal version 1.16.10262.0 ### Windows build number 10.0.22621.1413 ### Other Software Only Windows Command Prompt. ### Steps to reproduce Running a slightly modified version of compiled samples/ConPTY/EchoCon (however developed in C, not C++). The creation of Pipes and PseudoConsole is the same as in the example. ### Expected Behavior _No response_ ### Actual Behavior Randomly (<5% of the time), the function CreatePseudoConsole() crashes the program. When that happens, the program terminates with errorlevel -1073740940 (hex 0xc0000374 STATUS_HEAP_CORRUPTION). Tried to handle the exception, but it does not work with __try/__exception. The program works 95% of the time with no different inputs than when the problem happens. Any insights would be really appreciated.
claunia added the Needs-TriageIssue-BugNeeds-Author-FeedbackNo-Recent-Activity labels 2026-01-31 06:50:09 +00:00
Author
Owner

@lhecker commented on GitHub (Apr 10, 2023):

I would not attempt to catch a STATUS_HEAP_CORRUPTION anyways. As the name suggests, it indicates that your heap memory (the things allocated via malloc and HeapAlloc, etc.) have been corrupted and the safest thing you can do at that point is to exit (or crash). This can happen for instance if you free() the same pointer twice, or by simply writing out of bounds of an allocation (because this might overwrite the metadata stored next to your heap allocation).

While it is possible that ConPTY contains such an error I think it's somewhat unlikely, given how widely it is used (VS Code uses it for instance). Because of this, I think an error is more likely to be found in the code you wrote before the call to CreatePseudoConsole. If you've accidentally corrupted your heap before the call you can still end up seeing it attributed to CreatePseudoConsole, because that function tries to allocate some memory and if it's the first to encounter the already broken heap structures, it'll throw a STATUS_HEAP_CORRUPTION.

If your code is still similar to the example code, and if you're okay with posting it here, I'd be happy to review your code if you'd like. 🙂

@lhecker commented on GitHub (Apr 10, 2023): I would not attempt to catch a `STATUS_HEAP_CORRUPTION` anyways. As the name suggests, it indicates that your heap memory (the things allocated via `malloc` and `HeapAlloc`, etc.) have been corrupted and the safest thing you can do at that point is to exit (or crash). This can happen for instance if you `free()` the same pointer twice, or by simply writing out of bounds of an allocation (because this might overwrite the metadata stored next to your heap allocation). While it is possible that ConPTY contains such an error I think it's somewhat unlikely, given how widely it is used (VS Code uses it for instance). Because of this, I think an error is more likely to be found in the code you wrote before the call to `CreatePseudoConsole`. If you've accidentally corrupted your heap before the call you can still end up seeing it attributed to `CreatePseudoConsole`, because that function tries to allocate some memory and if it's the first to encounter the already broken heap structures, it'll throw a `STATUS_HEAP_CORRUPTION`. If your code is still similar to the example code, and if you're okay with posting it here, I'd be happy to review your code if you'd like. 🙂
Author
Owner

@microsoft-github-policy-service[bot] commented on GitHub (Apr 21, 2023):

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@microsoft-github-policy-service[bot] commented on GitHub (Apr 21, 2023): This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for **4 days**. It will be closed if no further activity occurs **within 3 days of this comment**.
Author
Owner

@microsoft-github-policy-service[bot] commented on GitHub (Apr 21, 2023):

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@microsoft-github-policy-service[bot] commented on GitHub (Apr 21, 2023): This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for **4 days**. It will be closed if no further activity occurs **within 3 days of this comment**.
Author
Owner

@microsoft-github-policy-service[bot] commented on GitHub (Apr 21, 2023):

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.

@microsoft-github-policy-service[bot] commented on GitHub (Apr 21, 2023): This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for **4 days**. It will be closed if no further activity occurs **within 3 days of this comment**.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19664