From 55a9874d5ca6cb626de42c9c2756f1e3283e988f Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 9 Nov 2023 19:10:35 -0600 Subject: [PATCH] Fix leak in buffering text for UIA when unfocused (#16251) Notes in #16217 have the investigation. TL;DR: we'd always buffer text. Even if we're disabled (unfocused). When we're disabled, we'd _never_ clear the buffered text. Oops. Closes #16217 (cherry picked from commit d14524cd4cc4970bb1b6456f9667e2dd661b9854) Service-Card-Id: 91033138 Service-Version: 1.19 --- src/renderer/uia/UiaRenderer.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/renderer/uia/UiaRenderer.cpp b/src/renderer/uia/UiaRenderer.cpp index e58c227c561..f39bcbe4fbf 100644 --- a/src/renderer/uia/UiaRenderer.cpp +++ b/src/renderer/uia/UiaRenderer.cpp @@ -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 = std::wstring{}; + return S_OK; } @@ -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);