Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix leak in buffering text for UIA when unfocused #16251

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/renderer/uia/UiaRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ UiaEngine::UiaEngine(IUiaEventDispatcher* dispatcher) :
[[nodiscard]] HRESULT UiaEngine::Disable() noexcept
{
_isEnabled = false;

// If we had buffered any text from NotifyNewText, dump it. When we do come
// back around to actually paint, we will just no-op. No sense in keeping
// the data buffered.
_newOutput.clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not release any memory however. Additionally, it also doesn't clear _queuedOutput. Do we need to do that?

This comment contains one approach to clear the memory in the EndPaint() method: #16209 (comment)
In the Disable() case I'd release the memory whenever, let's say, _newOutput.capacity() >= 4096 or something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Derp yea, we can resize it too.

I didn't think we needed to clear out _queuedOutput, since we might technically be after EndPaint, but in the middle of a Present.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, good point.


return S_OK;
}

Expand Down Expand Up @@ -171,6 +177,10 @@ CATCH_RETURN();
[[nodiscard]] HRESULT UiaEngine::NotifyNewText(const std::wstring_view newText) noexcept
try
{
// GH#16217 - don't even buffer this text if we're disabled. We may never
// come around to write it out.
RETURN_HR_IF(S_FALSE, !_isEnabled);

if (!newText.empty())
{
_newOutput.append(newText);
Expand Down
Loading