Crash: _terminal (and other members?) used after freed in TermControl #6475

Closed
opened 2026-01-31 00:39:44 +00:00 by claunia · 4 comments
Owner

Originally created by @beviu on GitHub (Feb 16, 2020).

Originally assigned to: @DHowett-MSFT on GitHub.

Environment

Windows build number: [run `[Environment]::OSVersion` for powershell, or `ver` for cmd]
Windows Terminal version (if applicable): master (672010a1)

Any other software?

Steps to reproduce

  1. Open the terminal
  2. Put your mouse cursor on the + button to open a new tab
  3. Quickly click with the left mouse button and then click with the middle mouse button to open a tab and close it. If you do it right, you should get this error message (which might be a bug in and of itself?): image
  4. Don't click OK yet!
  5. Focus the terminal window, behind that error message.
  6. Repeat 3. Nothing will happen because the application is frozen while you click OK in the dialog.
  7. Click OK in the dialog.
  8. Now, the dialog closes and another dialog with the same error message opens. If it didn't open, you need to start again from 2. You'll need to train to click with the right timing.
  9. Click OK in the new dialog.
  10. Terminal crashes!

Expected behavior

No crash.

Actual behavior

Crash on this line: 941a44a464/src/cascadia/TerminalControl/TermControl.cpp (L563) because even though we check that this is still alive with weakThis, _terminal is null. Also, it seems that there are other places where we do check this but don't check members that could be null now because Close was called. It's scary!

Originally created by @beviu on GitHub (Feb 16, 2020). Originally assigned to: @DHowett-MSFT on GitHub. <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment ```none Windows build number: [run `[Environment]::OSVersion` for powershell, or `ver` for cmd] Windows Terminal version (if applicable): master (672010a1) Any other software? ``` # Steps to reproduce <!-- A description of how to trigger this bug. --> 1. Open the terminal 2. Put your mouse cursor on the <kbd>+</kbd> button to open a new tab 3. Quickly click with the left mouse button and then click with the middle mouse button to open a tab and close it. If you do it right, you should get this error message (which might be a bug in and of itself?): ![image](https://user-images.githubusercontent.com/56923875/74605546-4c7b0280-50c9-11ea-9e06-07c1c54c2304.png) 4. **Don't click <kbd>OK</kbd> yet!** 5. Focus the terminal window, behind that error message. 6. Repeat 3. Nothing will happen because the application is frozen while you click <kbd>OK</kbd> in the dialog. 7. Click <kbd>OK</kbd> in the dialog. 8. Now, the dialog closes and another dialog with the same error message opens. If it didn't open, you need to start again from 2. You'll need to train to click with the right timing. 9. Click <kbd>OK</kbd> in the new dialog. 10. Terminal crashes! # Expected behavior <!-- A description of what you're expecting, possibly containing screenshots or reference material. --> No crash. # Actual behavior <!-- What's actually happening? --> Crash on this line: https://github.com/microsoft/terminal/blob/941a44a46491e1a018419eb24c9d92d3b2640e55/src/cascadia/TerminalControl/TermControl.cpp#L563 because even though we check that `this` is still alive with `weakThis`, `_terminal` is null. Also, it seems that there are other places where we do check `this` but don't check members that could be null now because `Close` was called. It's scary!
Author
Owner

@DHowett-MSFT commented on GitHub (Feb 21, 2020):

Triaged this one into v1.0 - it's stability and reliability, sp p1

@DHowett-MSFT commented on GitHub (Feb 21, 2020): Triaged this one into v1.0 - it's stability and reliability, sp p1
Author
Owner

@DHowett-MSFT commented on GitHub (Feb 21, 2020):

The "c0000142" error is actually because powershell was started and its parent console object died before it had a chance. That one we just can't help here 😄

@DHowett-MSFT commented on GitHub (Feb 21, 2020): The "c0000142" error is actually because powershell was started and its parent console object died before it had a chance. That one we just can't help here :smile:
Author
Owner

@zadjii-msft commented on GitHub (Mar 6, 2020):

Okay I tried to to this naively and bluescreened my laptop. I'm not touching this, but @DHowett-MSFT has an idea of how to go about this, so I'm going to let him have it

@zadjii-msft commented on GitHub (Mar 6, 2020): Okay I tried to to this naively and bluescreened my laptop. I'm _not_ touching this, but @DHowett-MSFT has an idea of how to go about this, so I'm going to let him have it
Author
Owner

@ghost commented on GitHub (Apr 22, 2020):

:tada:This issue was addressed in #5051, which has now been successfully released as Windows Terminal Preview v0.11.1121.0.🎉

Handy links:

@ghost commented on GitHub (Apr 22, 2020): :tada:This issue was addressed in #5051, which has now been successfully released as `Windows Terminal Preview v0.11.1121.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v0.11.1121.0) * [Store Download](https://www.microsoft.com/store/apps/9n0dx20hk701?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#6475