Skip to content

[GTK4] Fix use-after-free crash in window-active focus handling - #3586

Merged
akurtakov merged 1 commit into
eclipse-platform:masterfrom
akurtakov:gtk4-fix-focus-window-crash
Sep 11, 2026
Merged

[GTK4] Fix use-after-free crash in window-active focus handling#3586
akurtakov merged 1 commit into
eclipse-platform:masterfrom
akurtakov:gtk4-fix-focus-window-crash

Conversation

@akurtakov

Copy link
Copy Markdown
Member

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)

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)
@github-actions

Copy link
Copy Markdown
Contributor

Test Results (linux)

  109 files  ±0    109 suites  ±0   14m 29s ⏱️ -25s
4 626 tests ±0  4 393 ✅ ±0  233 💤 ±0  0 ❌ ±0 
3 452 runs  ±0  3 368 ✅ ±0   84 💤 ±0  0 ❌ ±0 

Results for commit 0ff1cc1. ± Comparison against base commit 203695c.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 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 firstFixedHandle cache.
  • 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.

@akurtakov
akurtakov merged commit f9faaf1 into eclipse-platform:master Sep 11, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants