Skip to content

status-icon: use a weak ref for the ListNames callback - #219

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

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

Conversation

@climashscape

Copy link
Copy Markdown

Problem

Another use-after-free in the same tray-icon lifetime chain, this time in libxapp. Real coredump (2026-11-03 14:41:56):

#0 g_type_check_instance_is_fundamentally_a (libgobject)
#1 g_object_set (libgobject)
#2 libxapp.so.1 + 0x29bea
#3 libxapp.so.1 + 0x2bfdf
#4-#8 libgio async callback dispatch

Disassembly of the installed libxapp identifies +0x29bea as the g_object_set() in sync_skeleton() (it is followed by g_dbus_interface_skeleton_flush()), and +0x2bfdf as the call site in on_list_names_completed() (the function walks the ListNames result, matches org.x.StatusIconMonitor, then calls sync_skeleton()).

look_for_status_applet() passes a bare XAppStatusIcon * to the async ListNames call. The icon is owned by an SnItem; when the client exits, sn_item_dispose() clears item->status_icon, the icon is finalized, and the callback then uses freed memory (self->priv->interface_skeleton, self->priv->connection).

Fix

Use a GWeakRef for the async user data. on_list_names_completed() only proceeds if the icon is still alive; it frees the error/result/wrapper on every path and returns if the icon is gone.

Test

Same reproducer as the sn-item fix (register an SNI item and close the connection immediately, with a real monitor):

  • unpatched 3.2.4: this is the first crash observed, after 2 registrations.
  • patched build: OK: watcher survived 1000 registrations (300 x4, including the combined build).

Notes

look_for_status_applet() passes a bare XAppStatusIcon pointer. The
owning SnItem can be removed while ListNames is in flight and drops its
ref, finalizing the icon; on_list_names_completed() then uses freed
memory (g_bus_own_name_on_connection with a stale connection).

Pass a GWeakRef wrapper and bail out if the icon is gone.

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