Skip to content

[linux] Use GWeakRef for engine and parent in FlAccessibleNode - #188699

Merged
robert-ancell merged 2 commits into
flutter:masterfrom
robert-ancell:linux-accessible-node-gweakref
Jun 29, 2026
Merged

robert-ancell merged 2 commits into
flutter:masterfrom
robert-ancell:linux-accessible-node-gweakref

Conversation

@robert-ancell

Copy link
Copy Markdown
Contributor

FlAccessibleNode registered its engine and parent weak pointers on the node itself rather than on the target objects, so the pointers were never cleared when the engine or parent was destroyed. The AT-SPI bridge can keep nodes alive past engine teardown, so subsequent calls would dereference freed memory.

Store the engine and parent as GWeakRef and fetch a strong reference where needed, returning safely when the target has been destroyed. This matches the rest of the embedder. Add tests covering access after engine and parent destruction.

Fixes #188660

@robert-ancell
robert-ancell requested a review from a team as a code owner June 28, 2026 22:32
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 28, 2026
@github-actions github-actions Bot added engine flutter/engine related. See also e: labels. platform-linux Building on or for Linux specifically a: desktop Running on desktop team-linux Owned by the Linux platform team labels Jun 28, 2026
FlAccessibleNode registered its engine and parent weak pointers on the
node itself rather than on the target objects, so the pointers were
never cleared when the engine or parent was destroyed. The AT-SPI bridge
can keep nodes alive past engine teardown, so subsequent calls would
dereference freed memory.

Store the engine and parent as GWeakRef and fetch a strong reference
where needed, returning safely when the target has been destroyed. This
matches the rest of the embedder. Add tests covering access after engine
and parent destruction.

Fixes flutter#188660
@robert-ancell
robert-ancell force-pushed the linux-accessible-node-gweakref branch from 37e9d4e to 0a1432e Compare June 28, 2026 22:33

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors FlAccessibleNode to use GWeakRef for engine and parent references, and adds tests to ensure nodes survive engine and parent destruction. The review feedback points out that passing a potential nullptr from g_weak_ref_get directly to GLib casting macros (ATK_OBJECT and FL_ENGINE) will trigger critical warnings, and recommends checking for nullptr before casting. Additionally, the feedback suggests initializing both weak references in fl_accessible_node_init and using g_weak_ref_set in the property setter to prevent undefined behavior from re-initializing GWeakRef structures.

Initialize the engine weak reference in fl_accessible_node_init and set
it with g_weak_ref_set, matching the parent weak reference. This ensures
the GWeakRef is always initialized before dispose clears it, even if the
engine property is not set during construction.

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM!

@robert-ancell
robert-ancell enabled auto-merge June 28, 2026 23:45
@robert-ancell
robert-ancell added this pull request to the merge queue Jun 29, 2026
Merged via the queue into flutter:master with commit 7e982cb Jun 29, 2026
198 checks passed
@robert-ancell
robert-ancell deleted the linux-accessible-node-gweakref branch June 29, 2026 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop CICD Run CI/CD engine flutter/engine related. See also e: labels. platform-linux Building on or for Linux specifically team-linux Owned by the Linux platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Linux] Potential crash in FlAccessibleNode

2 participants