From 46b5edec224839e3407111f6a73890caf7be0c9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8ger=20Hanseg=C3=A5rd?= Date: Mon, 24 Jun 2024 17:59:11 +0200 Subject: [PATCH] Call VariantClear to free BSTR owned by VARIANT instance This is a minimal fix to reduce leaks of BSTR instances from QWindowsUiaMainProvider. Introducing a VARIANT wrapper can be done as a follow-up task. Task-number: QTBUG-126530 Change-Id: I0c146049644517aca1b6ad7b096833faf5296329 Reviewed-by: Oliver Wolff (cherry picked from commit a03931095dde102fdfac82e8f6dd874706cadc6f) Reviewed-by: Qt Cherry-pick Bot --- .../platforms/windows/uiautomation/qwindowsuiamainprovider.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp index 0f2e2d8a5c1..fd7af9ce839 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp @@ -146,6 +146,9 @@ void QWindowsUiaMainProvider::notifyValueChange(QAccessibleValueChangeEvent *eve clearVariant(&oldVal); setVariantString(event->value().toString(), &newVal); UiaRaiseAutomationPropertyChangedEvent(provider, UIA_ValueValuePropertyId, oldVal, newVal); + HRESULT hr = VariantClear(&newVal); // Free string allocated by setVariantString + Q_ASSERT(hr == S_OK); + Q_UNUSED(hr) } } else if (QAccessibleValueInterface *valueInterface = accessible->valueInterface()) { if (QWindowsUiaMainProvider *provider = providerForAccessible(accessible)) {