Eliminate two memory leaks (#16597)

In WindowsTerminal, there was a leak of a BSTR with every call to
ITextRangeProvider::GetText, and a failure to call VariantClear in
ITextRange::GetAttributeValue when the value stored in the variant is
VT_BSTR. These were fixed by switching to wil::unique_bstr and
wil::unique_variant.
This commit is contained in:
glenrgordon 2024-01-25 09:57:37 -06:00 committed by GitHub
parent f5898886be
commit da99d892f4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 5 deletions

View File

@ -92,8 +92,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
winrt::Windows::Foundation::IInspectable XamlUiaTextRange::GetAttributeValue(int32_t textAttributeId) const
{
// Call the function off of the underlying UiaTextRange.
VARIANT result;
THROW_IF_FAILED(_uiaProvider->GetAttributeValue(textAttributeId, &result));
wil::unique_variant result;
THROW_IF_FAILED(_uiaProvider->GetAttributeValue(textAttributeId, result.addressof()));
// Convert the resulting VARIANT into a format that is consumable by XAML.
switch (result.vt)
@ -189,9 +189,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
winrt::hstring XamlUiaTextRange::GetText(int32_t maxLength) const
{
BSTR returnVal;
THROW_IF_FAILED(_uiaProvider->GetText(maxLength, &returnVal));
return winrt::to_hstring(returnVal);
wil::unique_bstr returnVal;
THROW_IF_FAILED(_uiaProvider->GetText(maxLength, returnVal.put()));
return winrt::hstring{ returnVal.get(), SysStringLen(returnVal.get()) };
}
int32_t XamlUiaTextRange::Move(XamlAutomation::TextUnit unit,