[GTK4] Fix use-after-free crash in window-active focus handling - #3586
Merged
akurtakov merged 1 commit intoSep 11, 2026
Merged
Conversation
Control.gtk4_focus_window_event located the shell's focusable client SwtFixed by walking a fixed three levels of first-children from the window and caching the result. The cached handle was never invalidated, so once that widget was destroyed - a view or perspective change, or the shell being disposed on close - the next window-active event called gtk_widget_has_focus on freed memory and crashed with a SIGSEGV in GLib's type check. The walk was also unreliable: following only first-children, it reached the first menu bar item rather than the client fixed whenever the shell had a menu bar. Reference this.handle directly instead - the receiver's client-area SwtFixed, which is the intended focusable widget and needs no walking or caching. Assisted-by: Anthropic Claude Code (claude-opus-4-8)
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused change removes the dangling native handle while preserving intended focus behavior.
Pull request overview
Fixes a GTK4 use-after-free crash during window focus handling by removing unsafe widget traversal and caching.
Changes:
- Removes the stale
firstFixedHandlecache. - Uses the shell’s stable client-area handle directly.
File summaries
| File | Description |
|---|---|
Control.java |
Safely resolves the focusable GTK4 client widget. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Control.gtk4_focus_window_event located the shell's focusable client SwtFixed by walking a fixed three levels of first-children from the window and caching the result. The cached handle was never invalidated, so once that widget was destroyed - a view or perspective change, or the shell being disposed on close - the next window-active event called gtk_widget_has_focus on freed memory and crashed with a SIGSEGV in GLib's type check.
The walk was also unreliable: following only first-children, it reached the first menu bar item rather than the client fixed whenever the shell had a menu bar. Reference this.handle directly instead - the receiver's client-area SwtFixed, which is the intended focusable widget and needs no walking or caching.
Assisted-by: Anthropic Claude Code (claude-opus-4-8)