@samitouri / QOSamiQemu / commits / b6506de40f

ui/dbus-listener: remove dbus_filter on connection close

The dbus filter holds a strong reference to the DBusDisplayListener (via GDestroyNotify) to ensure the listener remains alive while the filter may still be running in another thread. This creates a reference cycle (ddl -> conn -> filter -> ddl) that prevents the listener from being freed. Break the cycle by connecting to the connection's "closed" signal and removing the filter when the connection closes. Fixes: commit fa88b85dea96 ("ui/dbus: filter out pending messages when scanout") Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Marc-André Lureau committed Mar 3, 2026 at 17:41 UTC b6506de40f475bd5befe086ac94b4ceac83040a8
1 file changed +15
ui/dbus-listener.c
+15
@@ -1181,6 +1181,20 @@ static void dbus_display_listener_setup_scanout_dmabuf_v2(DBusDisplayListener *d
1181 #endif
1182 }
1183
1184 +static void
1185 +dbus_conn_closed(GDBusConnection *conn,
1186 + gboolean remote_peer_vanished,
1187 + GError *error,
1188 + gpointer user_data)
1189 +{
1190 + DBusDisplayListener *ddl = DBUS_DISPLAY_LISTENER(user_data);
1191 +
1192 + if (ddl->dbus_filter) {
1193 + g_dbus_connection_remove_filter(ddl->conn, ddl->dbus_filter);
1194 + ddl->dbus_filter = 0;
1195 + }
1196 +}
1197 +
1198 static GDBusMessage *
1199 dbus_filter(GDBusConnection *connection,
1200 GDBusMessage *message,
@@ -1262,6 +1276,7 @@ dbus_display_listener_new(const char *bus_name,
1276 }
1277
1278 ddl->dbus_filter = g_dbus_connection_add_filter(conn, dbus_filter, g_object_ref(ddl), g_object_unref);
1279 + g_signal_connect(conn, "closed", G_CALLBACK(dbus_conn_closed), ddl);
1280 ddl->bus_name = g_strdup(bus_name);
1281 ddl->conn = conn;
1282 ddl->console = console;