fix(linux): guard against GTK/Flutter lifecycle race during window destruction - #7
Draft
julianjc84 wants to merge 1 commit into
Draft
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
get_window() cast the toplevel widget to GtkWindow* and returned it unconditionally. During window destruction the toplevel is no longer a GtkWindow, so callers dereferenced an invalid pointer and crashed in libgtk-3.so - with Gtk-CRITICAL "GTK_IS_WINDOW (window)" assertions on the way down. Make get_window()/get_gdk_window() validate with GTK_IS_WINDOW() and return nullptr once the window is gone. As a direct consequence, every method handler that used the result must now null-check it; each returns a benign default (false / zeroed bounds / no-op) instead of operating on a dead window. Also harden the input path against stale GdkDevice pointers that trigger Gdk-CRITICAL during the same teardown: - ungrab_keyboard(): validate grab_pointer with GDK_IS_DEVICE() first - emit_button_release(): copy device/window from the press event No behavioral change while the window is live; these paths differ only once the window is being torn down.
julianjc84
force-pushed
the
fix/linux-nullptr-guards-sigsegv
branch
from
June 29, 2026 07:57
9612eb2 to
2690030
Compare
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.
Problem
Flutter's Linux embedder and GTK operate independent event loops with no coordinated window teardown. When a window is closing, GTK can destroy the underlying widget while Flutter's engine is still dispatching method channel calls to the plugin.
On macOS and Windows, the platform embedders have synchronous lifecycle hooks (NSWindowDelegate, Win32 WM_CLOSE/WM_DESTROY sequence) that ensure the engine winds down before the window is gone. Linux/GTK has no equivalent — the delete-event signal fires but GTK can proceed with destruction on the same event loop iteration.
This causes three crash paths:
get_window()— returnsGTK_WINDOW(gtk_widget_get_toplevel(...))withoutGTK_IS_WINDOW()validation. During destruction the toplevel is no longer a GtkWindow → SIGSEGV in all 42 caller functions.emit_button_release()— creates a synthetic GDK_BUTTON_RELEASE without setting device/window fields → Gdk-CRITICAL on null device.ungrab_keyboard()— uses a stored GdkDevice* that can be invalidated during drag operations → SIGSEGV.Fix
GTK_IS_WINDOW()check inget_window(), return nullptr if invalidGDK_IS_DEVICE()validation before ungrabregister_with_registrar()before connecting signalsCompanion PR
A related fix on the Flutter/Dart side guards the callers that invoke these plugin methods during window close:
rustdesk/rustdesk — fix(linux): guard window queries during close to prevent SIGSEGV
Both fixes together fully eliminate the SIGSEGV crashes. This PR stands on its own — it makes the plugin safe regardless of caller behaviour.
🤖 Generated with Claude Code