Skip to content

Commit 0681596

Browse files
zadjii-msftDHowett
authored andcommitted
Leak the window when it closes on Windows 10 (#15397)
Re: #15384 Basically, when we close a `DesktopWindowXamlSource`, it calls to `Windows_UI_Xaml!DirectUI::MetadataAPI::Reset`, which resets the XAML metadata provider _for the process_. So, closing one DWXS on one thread will force an A/V next time another thread tries to do something like... display a tooltip. Not immediately, but surely soon enough. This was fixed in Windows 11 by os.2020!5837001. That wasn't backported to Windows 10. This will cause a ~15MB memory leak PER WINDOW. OBVIOUSLY, this is bad, but it's less bad than crashing. We're gonna keep using #15384 for other ideas here too. (cherry picked from commit c589784) Service-Card-Id: 89283538 Service-Version: 1.18
1 parent a5c351c commit 0681596

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/cascadia/WindowsTerminal/IslandWindow.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,46 @@ IslandWindow::~IslandWindow()
4242

4343
void IslandWindow::Close()
4444
{
45+
static const bool isWindows11 = []() {
46+
OSVERSIONINFOEXW osver{};
47+
osver.dwOSVersionInfoSize = sizeof(osver);
48+
osver.dwBuildNumber = 22000;
49+
50+
DWORDLONG dwlConditionMask = 0;
51+
VER_SET_CONDITION(dwlConditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL);
52+
53+
if (VerifyVersionInfoW(&osver, VER_BUILDNUMBER, dwlConditionMask) != FALSE)
54+
{
55+
return true;
56+
}
57+
return false;
58+
}();
59+
60+
if (!isWindows11)
61+
{
62+
// BODGY
63+
// ____ ____ _____ _______ __
64+
// | _ \ / __ \| __ \ / ____\ \ / /
65+
// | |_) | | | | | | | | __ \ \_/ /
66+
// | _ <| | | | | | | | |_ | \ /
67+
// | |_) | |__| | |__| | |__| | | |
68+
// |____/ \____/|_____/ \_____| |_|
69+
//
70+
// There's a bug in Windows 10 where closing a DesktopWindowXamlSource
71+
// on any thread will free an internal static resource that's used by
72+
// XAML for the entire process. This would result in closing window
73+
// essentially causing the entire app to crash.
74+
//
75+
// To avoid this, leak the XAML island. We only need to leak this on
76+
// Windows 10, since the bug is fixed in Windows 11.
77+
//
78+
// See GH #15384, MSFT:32109540
79+
auto a{ _source };
80+
winrt::detach_abi(_source);
81+
82+
// </BODGY>
83+
}
84+
4585
if (_source)
4686
{
4787
_source.Close();

0 commit comments

Comments
 (0)