Repository: microsoft/terminal (language: cpp)

Issue:
WindowsTerminal.exe leak (never exit) after the `wtd.exe new-tab ...` command line process exits.
### Windows Terminal version

latest commit of main branch

### Windows build number

10.0.22631.0

### Other Software

_No response_

### Steps to reproduce

Execute the following command on the command line:
```
wtd.exe new-tab ping.exe localhost
```

### Expected Behavior

There is only one WindowsTerminal.exe process after the ping command ends

### Actual Behavior

Each time the above command is executed, there will be one more WindowsTerminal.exe process.

I debugged the redundant WindowsTerminal.exe process and found that it was stuck on the line highlighted in the picture below.
`D:\1\winterm\packages\Microsoft.Windows.ImplementationLibrary.1.0.230824.2\include\wil\filesystem.h`

![image](https://github.com/microsoft/terminal/assets/15074472/ffed717b-3d10-466c-83cd-ede1950cbdfd)

I guessed it might be related to `Microsoft.Windows.ImplementationLibrary`, and then revert this PR https://github.com/microsoft/terminal/pull/16120
After recompiling and building, the problem disappeared and there were no redundant leaking processes.



Discussion / hints:
Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!


### Closed similar issues:
- [Closing last tab crashes WindowsTerminal.exe (#1552)](https://github.com/microsoft/terminal/issues/1552),  similarity score: 0.81

> Note: You can give me feedback by thumbs upping or thumbs downing this comment.
Thanks for filing this!

I noticed this a few weeks back and totally forgot to file or investigate it. I'm guessing we're starting up the settings file watcher as we do the handoff to the monarch, but then never closing. 
Oh, @zadjii-msft, this is the one that was caused by https://github.com/microsoft/wil/pull/326.

It may have been fixed in https://github.com/microsoft/wil/pull/386

Which we should ingest!
(it hasn't been shipped to the nuget feed yet)

Fix patch:
diff --git a/dep/nuget/packages.config b/dep/nuget/packages.config
index e401b157d67..e6fd7ec3a68 100644
--- a/dep/nuget/packages.config
+++ b/dep/nuget/packages.config
@@ -9,7 +9,7 @@
   <package id="Microsoft.VisualStudio.Setup.Configuration.Native" version="2.3.2262" targetFramework="native" developmentDependency="true" />
   <package id="Microsoft.UI.Xaml" version="2.8.4" targetFramework="native" />
   <package id="Microsoft.Web.WebView2" version="1.0.1661.34" targetFramework="native" />
-  <package id="Microsoft.Windows.ImplementationLibrary" version="1.0.230824.2" targetFramework="native" developmentDependency="true" />
+  <package id="Microsoft.Windows.ImplementationLibrary" version="1.0.240122.1" targetFramework="native" developmentDependency="true" />
 
   <!-- Managed packages -->
   <package id="Appium.WebDriver" version="3.0.0.2" targetFramework="net45" />
diff --git a/src/common.nugetversions.targets b/src/common.nugetversions.targets
index 1c152920d22..f3cb03f6cb8 100644
--- a/src/common.nugetversions.targets
+++ b/src/common.nugetversions.targets
@@ -62,7 +62,7 @@
     <Import Project="$(MSBuildThisFileDirectory)..\build\rules\Microsoft.UI.Xaml.Additional.targets" Condition="'$(TerminalMUX)' == 'true'" />
 
     <!-- WIL (so widely used that this one does not have a TerminalWIL opt-in property; it is automatic) -->
-    <Import Project="$(MSBuildThisFileDirectory)..\packages\Microsoft.Windows.ImplementationLibrary.1.0.230824.2\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('$(MSBuildThisFileDirectory)..\packages\Microsoft.Windows.ImplementationLibrary.1.0.230824.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
+    <Import Project="$(MSBuildThisFileDirectory)..\packages\Microsoft.Windows.ImplementationLibrary.1.0.240122.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('$(MSBuildThisFileDirectory)..\packages\Microsoft.Windows.ImplementationLibrary.1.0.240122.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
 
   </ImportGroup>
 
@@ -93,7 +93,7 @@
     <Error Condition="'$(TerminalMUX)' == 'true' AND !Exists('$(MSBuildThisFileDirectory)..\packages\Microsoft.Web.WebView2.1.0.1661.34\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(MSBuildThisFileDirectory)..\packages\Microsoft.Web.WebView2.1.0.1661.34\build\native\Microsoft.Web.WebView2.targets'))" />
 
     <!-- WIL (so widely used that this one does not have a TerminalWIL opt-in property; it is automatic) -->
-    <Error Condition="!Exists('$(MSBuildThisFileDirectory)..\packages\Microsoft.Windows.ImplementationLibrary.1.0.230824.2\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(MSBuildThisFileDirectory)..\packages\Microsoft.Windows.ImplementationLibrary.1.0.230824.2\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
+    <Error Condition="!Exists('$(MSBuildThisFileDirectory)..\packages\Microsoft.Windows.ImplementationLibrary.1.0.240122.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(MSBuildThisFileDirectory)..\packages\Microsoft.Windows.ImplementationLibrary.1.0.240122.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
 
   </Target>
 
diff --git a/src/renderer/atlas/BackendD3D.cpp b/src/renderer/atlas/BackendD3D.cpp
index e68fb2a7a57..69d597ed0bd 100644
--- a/src/renderer/atlas/BackendD3D.cpp
+++ b/src/renderer/atlas/BackendD3D.cpp
@@ -468,7 +468,7 @@ void BackendD3D::_recreateCustomShader(const RenderingPayload& p)
         {
             if (error)
             {
-                LOG_HR_MSG(hr, "%*hs", error->GetBufferSize(), error->GetBufferPointer());
+                LOG_HR_MSG(hr, "%.*hs", static_cast<int>(error->GetBufferSize()), static_cast<char*>(error->GetBufferPointer()));
             }
             else
             {


Test patch: