Repository: microsoft/terminal (language: cpp)

Issue:
Crash after  `Export Text`
### Windows Terminal version

main 7061c54

### Windows build number

10.0.19044.0

### Other Software

_No response_

### Steps to reproduce

`Export Text` to save buffer to file.

### Expected Behavior

Buffer content saved. No crashes.

### Actual Behavior

After `Export Text` terminal crashes. The export is successful though.

```
*******************************************************************************
*                                                                             *
*                        Exception Analysis                                   *
*                                                                             *
*******************************************************************************


KEY_VALUES_STRING: 1

    Key  : AV.Dereference
    Value: NullPtr

    Key  : AV.Fault
    Value: Read

    Key  : Analysis.CPU.mSec
    Value: 7999

    Key  : Analysis.DebugAnalysisManager
    Value: Create

    Key  : Analysis.Elapsed.mSec
    Value: 47561

    Key  : Analysis.Init.CPU.mSec
    Value: 765

    Key  : Analysis.Init.Elapsed.mSec
    Value: 48332

    Key  : Analysis.Memory.CommitPeak.Mb
    Value: 278

    Key  : Timeline.OS.Boot.DeltaSec
    Value: 123950

    Key  : Timeline.Process.Start.DeltaSec
    Value: 3136

    Key  : WER.OS.Branch
    Value: vb_release

    Key  : WER.OS.Timestamp
    Value: 2019-12-06T14:06:00Z

    Key  : WER.OS.Version
    Value: 10.0.19041.1


NTGLOBALFLAG:  0

PROCESS_BAM_CURRENT_THROTTLED: 0

PROCESS_BAM_PREVIOUS_THROTTLED: 0

APPLICATION_VERIFIER_FLAGS:  0

EXCEPTION_RECORD:  (.exr -1)
ExceptionAddress: 00007ffb353c1bf3 (TerminalApp!winrt::impl::consume_Microsoft_Terminal_Settings_Model_IActionEventArgs<winrt::Microsoft::Terminal::Settings::Model::ActionEventArgs>::Handled+0x0000000000000053)
   ExceptionCode: c0000005 (Access violation)
  ExceptionFlags: 00000000
NumberParameters: 2
   Parameter[0]: 0000000000000000
   Parameter[1]: 0000000000000000
Attempt to read from address 0000000000000000

FAULTING_THREAD:  00003390

PROCESS_NAME:  WindowsTerminal.exe

READ_ADDRESS:  0000000000000000 

ERROR_CODE: (NTSTATUS) 0xc0000005 - The instruction at 0x%p referenced memory at 0x%p. The memory could not be %s.

EXCEPTION_CODE_STR:  c0000005

EXCEPTION_PARAMETER1:  0000000000000000

EXCEPTION_PARAMETER2:  0000000000000000

STACK_TEXT:  
00000098`a3f4d3a0 00007ffb`353c6631     : 000001e6`791b0340 00000098`a3f4d450 000001e6`80440350 00000098`a3f4d4b8 : TerminalApp!winrt::impl::consume_Microsoft_Terminal_Settings_Model_IActionEventArgs<winrt::Microsoft::Terminal::Settings::Model::ActionEventArgs>::Handled+0x53
00000098`a3f4d3f0 00007ffb`353b983a     : 00000098`00000002 000001e6`7e18fee0 00000000`00000000 00007ffb`66749c63 : TerminalApp!winrt::TerminalApp::implementation::TerminalPage::_HandleExportBuffer+0x121
00000098`a3f4d480 00007ffb`353d4ae4     : 000001e6`804b4701 000001e6`7e2ffa18 000001e6`7e2ffa10 000001e6`804404d0 : TerminalApp!`winrt::TerminalApp::implementation::TerminalPage::_InitializeTab'::`2'::<lambda_5>::operator()+0x10a
00000098`a3f4d4f0 00007ffb`353d43e8     : 000001e6`00000000 00007ffb`352cd61d 000001e6`79274a30 00000000`00000000 : TerminalApp!winrt::impl::invoke<winrt::delegate<> >+0x14
00000098`a3f4d520 00007ffb`353d4db8     : 000001e6`80440350 00000098`a3f4d610 00000000`00000000 00007ffb`66862bdc : TerminalApp!winrt::event<winrt::delegate<> >::operator()<>+0x78
00000098`a3f4d560 00007ffb`668629c1     : 000001e6`804a4520 00000000`00000000 000001e6`81a45360 00000000`00000000 : TerminalApp!winrt::impl::delegate<winrt::Windows::UI::Xaml::RoutedEventHandler,`winrt::TerminalApp::implementation::TerminalTab::_CreateContextMenu'::`6'::<lambda_7> >::Invoke+0x78
00000098`a3f4d5b0 00007ffb`66e3491e     : 00000000`00000000 000001e6`804a8ad8 000001e6`81a45360 000001e6`00000000 : Windows_UI_Xaml!GetErrorContextIndex+0x127f41
00000098`a3f4d650 00007ffb`66e35794     : 00000000`00000000 000001e6`8047f510 00000000`00000000 000001e6`81a45360 : Windows_UI_Xaml!GetStringRawBuffer+0xc315e
00000098`a3f4d6b0 00007ffb`66e355c2     : 000001e6`8419b501 00000000`00000000 000001e6`8419b530 000001e6`79274a30 : Windows_UI_Xaml!GetStringRawBuffer+0xc3fd4
00000098`a3f4d6e0 00007ffb`66ff08ce     : 00000000`00000000 000001e6`804a8ad0 000001e6`804b4701 000001e6`804a8ad0 : Windows_UI_Xaml!GetStringRawBuffer+0xc3e02
00000098`a3f4d710 00007ffb`66a5e95f     : 00000000`00000000 00000000`00000000 000001e6`8380d330 00000000`00000000 : Windows_UI_Xaml!GetStringRawBuffer+0x27f10e
00000098`a3f4d740 00007ffb`667ee46d     : 000001e6`804a8ad0 000001e6`84866630 000001e6`804b4700 000001e6`804b4700 : Windows_UI_Xaml!DllMain+0x6d0ff
00000098`a3f4d780 00007ffb`667ee1ed     : 000001e6`0000000e 00000000`00000000 00000000`0000000c 000001e6`8419b530 : Windows_UI_Xaml!GetErrorContextIndex+0xb39ed
00000098`a3f4d850 00007ffb`6691c75a     : 00000000`00000000 00000000`0000000c 000001e6`844ab4d0 00007ffb`666b26c5 : Windows_UI_Xaml!GetErrorContextIndex+0xb376d
00000098`a3f4d890 00007ffb`667b5708     : 000001e6`79281040 00000098`a3f4de48 000001e6`79281040 00007ffb`862a9877 : Windows_UI_Xaml!DllGetActivationFactory+0x2614a
00000098`a3f4d920 00007ffb`667b54ea     : 000001e6`79281040 00000000`00000001 0000d60e`344a0ad0 00000098`a3f4edd8 : Windows_UI_Xaml!GetErrorContextIndex+0x7ac88
00000098`a3f4da00 00007ffb`845ee7e8     : 00000098`a3f4dd90 00000000`80000022 00000000`00000000 00000000`00000001 : Windows_UI_Xaml!GetErrorContextIndex+0x7aa6a
00000098`a3f4da50 00007ffb`845ee36c     : 00000000`001607b4 00007ffb`667b5460 00000000`001607b4 00005641`00000415 : user32!UserCallWinProcCheckWow+0x2f8
00000098`a3f4dbe0 00007ffb`84600f93     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000018 : user32!DispatchClientMessage+0x9c
00000098`a3f4dc40 00007ffb`86330ba4     : 00000000`00000001 00000098`00000018 00000098`00000000 00007ffb`666f0200 : user32!_fnDWORD+0x33
00000098`a3f4dca0 00007ffb`842a1124     : 00007ffb`845ede92 00000000`000000ec 00007ffb`00000018 00000000`00000000 : ntdll!KiUserCallbackDispatcherContinue
00000098`a3f4dd28 00007ffb`845ede92     : 00000000`000000ec 00007ffb`00000018 00000000`00000000 00000000`00000088 : win32u!NtUserMessageCall+0x14
00000098`a3f4dd30 00007ffb`845ed61a     : 00000000`001607b4 000001e6`00000000 00000000`00000000 00000000`00000415 : user32!SendMessageWorker+0x7f2
00000098`a3f4ddd0 00007ffb`668f0cd7     : 00000000`000000a0 00007ffb`668f0ba0 000001e6`792798e0 00000098`a3f4e220 : user32!SendMessageW+0xda
00000098`a3f4de20 00007ffb`6676da83     : 00000000`0000000c 00007ffb`668f0ba0 000001e6`8419b530 00000000`00000000 : Windows_UI_Xaml!GetErrorContextIndex+0x1b6257
00000098`a3f4deb0 00007ffb`6676d485     : 000001e6`79276cd0 000001e6`8418000c 00000098`00000001 000001e6`84186900 : Windows_UI_Xaml!GetErrorContextIndex+0x33003
00000098`a3f4dfb0 00007ffb`66ba5910     : 000001e6`792823b0 000001e6`79277fe0 000001e6`79277f00 000001e6`8419b530 : Windows_UI_Xaml!GetErrorContextIndex+0x32a05
00000098`a3f4e050 00007ffb`66ba4444     : 000001e6`00000001 000001e6`8396b710 00000000`00000000 000001e6`83ae7b10 : Windows_UI_Xaml!OverrideXamlResourcePropertyBag+0x55c70
00000098`a3f4e0d0 00007ffb`66ba56b5     : 00000000`00000000 00000000`00000000 00000000`00000000 00000098`a3f4e220 : Windows_UI_Xaml!OverrideXamlResourcePropertyBag+0x547a4
00000098`a3f4e180 00007ffb`66d19276     : 000001e6`841869d0 000001e6`81ac61b0 00000000`00000000 00000098`00000000 : Windows_UI_Xaml!OverrideXamlResourcePropertyBag+0x55a15
00000098`a3f4e1b0 00007ffb`66f83566     : 000001e6`841869d0 000001e6`81ac61b0 00000000`00000000 00007ffb`862e07b0 : Windows_UI_Xaml!OverrideXamlResourcePropertyBag+0x1c95d6
00000098`a3f4e1e0 00007ffb`66f837c2     : 00000000`00000000 432b0000`43730000 000000ab`000000f3 000001e6`841869d0 : Windows_UI_Xaml!GetStringRawBuffer+0x211da6
00000098`a3f4e3d0 00007ffb`7e79b0a8     : 00000000`00000001 00000000`00000001 000001e6`840f4c4c 000001e6`83cf8b78 : Windows_UI_Xaml!GetStringRawBuffer+0x212002
00000098`a3f4e400 00007ffb`7e7a0798     : 000001e6`7ac90000 00000000`00000000 000001e6`83cf88c0 00007ffb`00004a6a : NInput!COutputConverter::Process+0x46c
00000098`a3f4e5c0 00007ffb`7e7bf27f     : 00000000`00000001 000001e6`83cf88c0 000001e6`840f4ca8 00000000`00000000 : NInput!CInteractionContextImpl::OutputCallback+0x128
00000098`a3f4e6b0 00007ffb`7e7bf246     : 00000098`a3f4e750 00000000`00000040 00000098`a3f4e890 00000000`00000000 : NInput!CInteractionGroupingFilter::_SendOutput+0x1f
00000098`a3f4e6f0 00007ffb`7e7be9fa     : 000001e6`840f4c38 00000000`00000002 00000001`00000000 00000000`00000001 : NInput!CInteractionGroupingFilter::_OnInput+0x7e
00000098`a3f4e720 00007ffb`7e7beacf     : 000001e6`840f4c38 00000000`00000002 00000000`00000001 00000000`00000000 : NInput!COutputCoalescingFilter::Flush+0xbe
00000098`a3f4e750 00007ffb`7e7bd3ea     : 000001e6`840f4be0 00000000`00000002 000001e6`840f4be0 00000000`00000001 : NInput!COutputCoalescingFilter::_OnInput+0x43
00000098`a3f4e780 00007ffb`7e7a11b0     : 0000001c`da0df4a8 00000000`00000000 00000098`a3f4e8d0 000001e6`83cf88c0 : NInput!CInteractionEngineImpl::DigitizerInput+0x262
00000098`a3f4e830 00007ffb`7e79f25c     : 00000000`00000060 00000098`a3f4ee80 00000098`a3f4ee88 000001e6`846048d0 : NInput!CInteractionContextImpl::ProcessFrameHistory+0x65c
00000098`a3f4eda0 00007ffb`66f826d5     : 000001e6`81ac6180 000001e6`846048d0 00000098`a3f4ee50 00000000`00000001 : NInput!ProcessPointerFramesInteractionContext+0x17c
00000098`a3f4edd0 00007ffb`66f8296e     : 000001e6`00000001 00007ffb`00000001 000040b8`00000001 000001e6`00000001 : Windows_UI_Xaml!GetStringRawBuffer+0x210f15
00000098`a3f4ee80 00007ffb`66ba55d4     : 00000000`00000000 000001e6`81ac6180 000001e6`792792b0 00000000`00000000 : Windows_UI_Xaml!GetStringRawBuffer+0x2111ae
00000098`a3f4eeb0 00007ffb`66ba4826     : 00000000`00000000 000001e6`00000001 000001e6`847c45a0 00000000`00000000 : Windows_UI_Xaml!OverrideXamlResourcePropertyBag+0x55934
00000098`a3f4ef90 00007ffb`66f88b70     : 000001e6`792798e0 000001e6`00000001 000001e6`847c45a0 000001e6`79279a40 : Windows_UI_Xaml!OverrideXamlResourcePropertyBag+0x54b86
00000098`a3f4f040 00007ffb`66ae3f9e     : 00000001`0762d400 00000000`00000000 000001e6`847c3f60 000001e6`79277fe0 : Windows_UI_Xaml!GetStringRawBuffer+0x2173b0
00000098`a3f4f1c0 00007ffb`668ae804     : 00000000`00000000 00000098`a3f4f258 00000098`a3f4f2c1 000001e6`847c45a0 : Windows_UI_Xaml!DllMain+0xf273e
00000098`a3f4f210 00007ffb`668ae72c     : 00000000`00000247 00000098`a3f4f2c1 000001e6`00000001 000001e6`00000001 : Windows_UI_Xaml!GetErrorContextIndex+0x173d84
00000098`a3f4f240 00007ffb`66da91f8     : 00000000`00280908 00000000`00000247 000001e6`79274a30 000001e6`7e3c9b90 : Windows_UI_Xaml!GetErrorContextIndex+0x173cac
00000098`a3f4f320 00007ffb`66da905f     : 00000000`00000247 00000000`20020000 00000000`00000247 00000000`20020001 : Windows_UI_Xaml!GetStringRawBuffer+0x37a38
00000098`a3f4f3e0 00007ffb`66d78920     : 00000000`02d00633 00000000`000403ae 00000000`20020001 00000000`000403ae : Windows_UI_Xaml!GetStringRawBuffer+0x3789f
00000098`a3f4f430 00007ffb`66b79746     : 00000000`20020001 00000000`20020001 00000000`000403ae 00007ffb`845e9f71 : Windows_UI_Xaml!GetStringRawBuffer+0x7160
00000098`a3f4f480 00007ffb`66b7b7e1     : 00000000`000403ae 00000000`00000247 00005818`1601078c 00000000`00000001 : Windows_UI_Xaml!OverrideXamlResourcePropertyBag+0x29aa6
00000098`a3f4f4d0 00007ffb`845ee7e8     : 00000000`00000001 00000098`a3f4f820 00000000`00000002 00000000`00000001 : Windows_UI_Xaml!OverrideXamlResourcePropertyBag+0x2bb41
00000098`a3f4f510 00007ffb`845ee229     : 00000000`000002d0 00007ffb`66b7b730 00000000`000403ae 00007ffb`00000247 : user32!UserCallWinProcCheckWow+0x2f8
00000098`a3f4f6a0 00007ff7`b5bd6383     : 00007ffb`66b7b730 00000000`00000005 00000000`00000000 00000000`00000000 : user32!DispatchMessageWorker+0x249
00000098`a3f4f720 00007ff7`b5c04562     : 00000000`00000005 00000000`00000000 00000000`00000000 00000000`00000000 : WindowsTerminal!wWinMain+0x4c3
00000098`a3f4f990 00007ffb`842f7034     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : WindowsTerminal!__scrt_common_main_seh+0x106
00000098`a3f4f9d0 00007ffb`862e2651     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : KERNEL32!BaseThreadInitThunk+0x14
00000098`a3f4fa00 00000000`00000000     : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x21


STACK_COMMAND:  ~0s ; .cxr ; kb

FAULTING_SOURCE_LINE:  C:\GitHub\terminal\src\cascadia\TerminalApp\Generated Files\winrt\Microsoft.Terminal.Settings.Model.h

FAULTING_SOURCE_FILE:  C:\GitHub\terminal\src\cascadia\TerminalApp\Generated Files\winrt\Microsoft.Terminal.Settings.Model.h

FAULTING_SOURCE_LINE_NUMBER:  81

SYMBOL_NAME:  TerminalApp!winrt::impl::consume_Microsoft_Terminal_Settings_Model_IActionEventArgs<winrt::Microsoft::Terminal::Settings::Model::ActionEventArgs>::Handled+53

MODULE_NAME: TerminalApp

IMAGE_NAME:  TerminalApp.dll

FAILURE_BUCKET_ID:  NULL_POINTER_READ_c0000005_TerminalApp.dll!winrt::impl::consume_Microsoft_Terminal_Settings_Model_IActionEventArgs_winrt::Microsoft::Terminal::Settings::Model::ActionEventArgs_::Handled

OS_VERSION:  10.0.19041.1

BUILDLAB_STR:  vb_release

OSPLATFORM_TYPE:  x64

OSNAME:  Windows 10

FAILURE_ID_HASH:  {a8ad03d1-6f8c-445e-d1b9-cfa3b022a10f}

Followup:     MachineOwner 
```


Discussion / hints:

Fix patch:
diff --git a/src/cascadia/TerminalApp/AppActionHandlers.cpp b/src/cascadia/TerminalApp/AppActionHandlers.cpp
index c8dbacbcbde..2088ad2c464 100644
--- a/src/cascadia/TerminalApp/AppActionHandlers.cpp
+++ b/src/cascadia/TerminalApp/AppActionHandlers.cpp
@@ -923,7 +923,10 @@ namespace winrt::TerminalApp::implementation
 
             // If we didn't have args, or the args weren't ExportBufferArgs (somehow)
             _ExportTab(*activeTab, L"");
-            args.Handled(true);
+            if (args)
+            {
+                args.Handled(true);
+            }
         }
     }
 


Test patch: