Improve TSF failure handling (#19965)

An internal AI correctly flagged that we aren't calling
`UnadviseSink()` in case a later `Initialize()` call fails.
We can easily fix this by calling `Uninitialize()`.
This commit is contained in:
Leonard Hecker
2026-03-11 21:31:04 +01:00
committed by GitHub
parent e2d51636cd
commit 36fb444d3e
2 changed files with 13 additions and 6 deletions

View File

@@ -14,7 +14,7 @@ Handle Handle::Create()
handle._impl = new Implementation();
if (FAILED(handle._impl->Initialize()))
{
delete handle._impl;
handle._destroy();
handle._impl = nullptr;
}
return handle;
@@ -32,11 +32,7 @@ void Handle::SetDefaultScopeAlphanumericHalfWidth(bool enable)
Handle::~Handle()
{
if (_impl)
{
_impl->Uninitialize();
_impl->Release();
}
_destroy();
}
Handle::Handle(Handle&& other) noexcept :
@@ -94,3 +90,12 @@ bool Handle::HasActiveComposition() const noexcept
{
return _impl ? _impl->HasActiveComposition() : false;
}
void Handle::_destroy() noexcept
{
if (_impl)
{
_impl->Uninitialize();
_impl->Release();
}
}

View File

@@ -51,6 +51,8 @@ namespace Microsoft::Console::TSF
bool HasActiveComposition() const noexcept;
private:
void _destroy() noexcept;
Implementation* _impl = nullptr;
};
}