Skip to content

gtk: fix crash caused by missing dbus connection - #13101

Merged
pluiedev merged 1 commit into
ghostty-org:mainfrom
dkinzler:fix/global-shortcuts-crash
Jun 26, 2026
Merged

pluiedev merged 1 commit into
ghostty-org:mainfrom
dkinzler:fix/global-shortcuts-crash

Conversation

@dkinzler

Copy link
Copy Markdown
Contributor

Fixes #13075 where GTK app will crash if a D-Bus connection can't be opened. If you have global keybinds set in your config, Ghostty will crash immediately in both debug and release builds. With no global keybinds it still crashes when you reload the config, but only in builds with safety checks enabled, due to a failed assertion.

This problem is rooted in GlobalShortcuts, which implements the XDG global shortcuts protocol. The refresh function is triggered every time the config changes and once on startup. If there are global keybinds in the config but no D-Bus connection, refresh will still try to setup the global keybinds by calling the request method, which will use priv.dbus_connection.? while the field is null. Depending on the build mode this either fails the Zig runtime safety check immediately or eventually causes a segmentation fault somewhere in gio/glib when the null pointer is used.
Additionally, even if there are no global keybinds set, Ghostty will still crash when the config is reloaded, because the close function exits early if dbus_connection is null and doesn't clean up the arena that was created in the first call to refresh on startup. The next call to refresh will then fail the priv.arena == null assertion. This only happens if built with safety checks enabled.

As a fix close will now always clean up the arena and refresh will exit early if there is no D-Bus connection.

To easily reproduce the crash, change Application.startupGlobalShortcuts (in src/apprt/gtk/class/application.zig) to set the D-Bus connection to null with priv.global_shortcuts.setDbusConnection(null). Then run with a global keybind e.g. ghostty --keybind="global:ctrl+o=toggle_quick_terminal".

AI Disclosure

No AI was used.

Changes GlobalShortcuts.refresh to do nothing when there is no dbus connection and GlobalShortcuts.close to always clean up arena memory.
@dkinzler
dkinzler requested a review from a team as a code owner June 26, 2026 10:55
@ghostty-bot ghostty-bot Bot added the gtk Issues exclusive to GTK which are not OS-specific label Jun 26, 2026

@pluiedev pluiedev 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.

Thanks!

@pluiedev
pluiedev merged commit 9f62873 into ghostty-org:main Jun 26, 2026
94 checks passed
@github-actions github-actions Bot added this to the 1.4.0 milestone Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gtk Issues exclusive to GTK which are not OS-specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants