Repository navigation
fix(win32): Fix UIA structure event crash and subtree provider leak - #26012
Merged
agneszitte merged 2 commits intoNov 4, 2026
Merged
Conversation
The native function is declared in UIAutomationCoreApi.h as UiaRaiseStructureChangedEvent(IRawElementProviderSimple*, StructureChangeType, int* pRuntimeId, int cRuntimeIdLen). The P/Invoke declared three parameters and marshalled the runtime id as a SAFEARRAY, so UIA read the SAFEARRAY header as the id array and took its length from an uninitialized register. Once a UIA client subscribes to StructureChanged events, a ChildRemoved raised with a runtime id intermittently crashes the process with an access violation in FlushStructureChanges -> UiaRaiseStructureChangedEvent. The try/catch around the call cannot catch it. Pass the runtime id as an int array with its length. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Backport of the provider-cleanup part of #23722 (master), complementing the owner release already backported to 6.x, with the cleanup-lookup correction from #25985. While a UIA client subscribes to StructureChanged events, providers of a removed subtree could stay connected and never be invalidated, so UIA's COM reference kept each provider, and through its owner the removed element tree, alive: - CleanupProviders walks the removed subtree top-down. Invalidating a provider calls UiaDisconnectProvider, during which UIA asks for its parent; the parent was cleaned a moment earlier, so a new provider was created for it and never invalidated. While a cleanup runs (_providerCleanupDepth), lookups now only return providers that already exist (peer key, then the owner's element key when it represents the same peer) and never create or register one. Lookups are not blocked outright: a connected parent must still resolve during the callback. - Providers registered only by automation peer (e.g. realized ListViewItems) are not in the element-keyed table, so the cleanup walk skipped them. CleanupProviders now resolves providers with TryGetExistingProviderForElement. Measured in an app that swaps record views in and out of a peer-bearing container, with a UIA client subscribed to StructureChanged (Subtree): 18 of 18 closed record views were retained on 6.8.0-dev.311, with the root path [COM/WinRT Objects] -> Win32RawElementProvider -> view. With this change, none are retained through a provider and the heap levels off. Adds the Given_Win32ProviderLifetime runtime tests from #25985, without the native-client test that needs the out-of-process probe. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
morning4coffe-dev
approved these changes
Nov 4, 2026
morning4coffe-dev
enabled auto-merge
November 4, 2026 07:55
Contributor
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GitHub Issue: related to unoplatform/kahua-private#564
PR Type:
🐞 Bugfix
What changed? 🚀
This is a follow-up to #25943, which backported only the owner release from #23722 to
release/stable/6.7. The client reports that the leak remains in their app, and that removing elements can crash. This PR brings their two patches, with the cleanup-lookup correction from #25985 folded into the second.1.
UiaRaiseStructureChangedEventsignature (crash). The P/Invoke marshalled the runtime ID as a SAFEARRAY and omitted the length argument. The native signature is(IRawElementProviderSimple*, StructureChangeType, int* pRuntimeId, int cRuntimeIdLen). When a UIA client subscribes to structure changes, aChildRemovedraised with a runtime ID can crash the process with an access violation (0xC0000005). Thetry/catcharound the call can't catch it. The P/Invoke now passes anint[]and its length. This is the same fix as #25985 on master.2. Every provider of a removed subtree is invalidated (leak). These parts come from #23722:
CleanupProvidersnow resolves each element's provider withTryGetExistingProviderForElement. That lookup also finds providers registered only by their peer, which the walk used to skip (e.g. realized ListViewItems, or an element whose peer belongs to another element).UiaDisconnectProvidercalls back into the provider it disconnects, includingNavigate(Parent). While a cleanup runs, lookups only return providers that already exist (peer key first, then the owner's element key when its provider represents the same peer), and nothing is created or registered. Before, a provider was created for the parent that had just been cleaned and was never invalidated, and UIA's reference to it kept the removed tree alive.The client's patch blocked every lookup during cleanup. With #25985's correction, a parent that is still connected keeps resolving during the callback.
The client measured the leak in their app with a UIA client subscribed to StructureChanged: 18 of 18 closed record views were retained on 6.8.0-dev.311, through
[COM/WinRT Objects] → Win32RawElementProvider → view. With 0002, none are retained through a provider and the heap levels off.Adds
Given_Win32ProviderLifetimefrom #25985, minus two tests:Given_Win32Accessibilityalready has from fix(win32): Fix UIA provider memory leak (partial backport of #23722) #25943.Validation
Runtime (Skia Win32,
SamplesApp.Skia.Genericnet10.0, local),Given_Win32*filter:Given_Win32Accessibility+Given_Win32ProviderLifetime)When_Cleanup_Reenters_Live_Provider_Lookupfails: a connected sibling resolves to nullWhen_Removed_Element_Uses_Another_Elements_Peer_Then_Provider_Is_Invalidatedfails: the provider keyed by the peer's owner stays connectedThe fail-before rows were run on
servicing/6.8;Win32Accessibility.csandWin32RawElementProvider.csare identical on both lines after this change, and the 13/13 run was repeated onrelease/stable/6.7.Not covered by an automated test:
Win32UiaEventProbein CI.PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code