Skip to content

Commit

Permalink
Eliminate two memory leaks (#16597)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
glenrgordon authored Jan 25, 2024
1 parent f589888 commit da99d89
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/cascadia/TerminalControl/XamlUiaTextRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit da99d89

Please sign in to comment.