Skip to content

sn-item: use a weak ref for async callbacks - #218

Open
climashscape wants to merge 1 commit into
linuxmint:3.2-maintenancefrom
climashscape:fix/sn-item-weak-ref
Open

climashscape wants to merge 1 commit into
linuxmint:3.2-maintenancefrom
climashscape:fix/sn-item-weak-ref

Conversation

@climashscape

Copy link
Copy Markdown

Problem

xapp-sn-watcher crashes with SIGSEGV when a StatusNotifierItem client registers and exits quickly. On Linux Mint 22.3 (xapp 3.2.4+mint22.3, Cinnamon 6.6.9) it happens repeatedly; every crash removes all SNI/XApp status icons from the panel until the watcher is restarted.

Real coredump (2026-11-12 20:53:29):

#0 g_type_check_instance
#1 g_signal_connect_data
#2 xapp-sn-watcher + 0xf41d

+0xf41d maps to property_proxy_acquired() in xapp-sn-watcher/sn-item.c: the call site is followed by xapp_status_icon_new(), and the strings Could not get property proxy for %s: %s, g-signal and highlight-both-menus are referenced there.

initialize_item() passes a bare SnItem * to the async g_dbus_proxy_new() for org.freedesktop.DBus.Properties. If the client exits before the callback, handle_sn_item_name_owner_lost() removes the item from the hash table (its only owner), the item is finalized, and the callback dereferences freed memory. The G_IO_ERROR_CANCELLED branch also falls through to g_signal_connect() instead of returning. get_all_properties_callback() has the same bare-pointer problem.

The existing 3.2 fix (#201/#214) only covers the cancellation handling in get_all_properties_callback(); it does not cover this callback.

Fix

Use GWeakRef for the async user data in both callbacks. The callback takes a temporary strong ref only if the item is still alive; if it is gone, it discards the result and returns. Every path frees the error/proxy/weak-ref wrapper. Return on any error, including G_IO_ERROR_CANCELLED.

A weak ref is used instead of g_object_ref: a strong ref would defer dispose and let an already-removed item create a status icon.

Reproduction

Under a private bus with a real XApp.StatusIconMonitor, register a StatusNotifierItem on a fresh connection and close the connection immediately after the registration reply. Repeat.

  • unpatched 3.2.4: watcher dies within 2-30 registrations.
  • patched 3.2.4: OK: watcher survived 1000 registrations (also 300 x3).

A standalone reproducer script is available and can be added to the PR if wanted.

Notes

property_proxy_acquired() and get_all_properties_callback() receive a
bare SnItem pointer. If the client exits while the call is in flight,
handle_sn_item_name_owner_lost() removes the item from the hash table
and it is finalized; the callback then writes to freed memory and
crashes in g_signal_connect_data.

Pass a GWeakRef wrapper instead. The callback takes a temporary strong
ref only if the item is still alive, and cleans up on every path. Also
fix the cancellation path, which previously fell through to
g_signal_connect() instead of returning.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant