+void
+adaptor_cleanup (void)
+{
+ GList *l;
+ GSList *ls;
+
+ if (!spi_global_app_data)
+ return;
+
+ spi_atk_tidy_windows ();
+ spi_atk_deregister_event_listeners ();
+
+ deregister_application (spi_global_app_data);
+
+ if (spi_global_app_data->bus)
+ {
+ dbus_connection_remove_filter (spi_global_app_data->bus, signal_filter, NULL);
+ droute_context_unregister (spi_global_app_data->droute, spi_global_app_data->bus);
+ dbus_connection_unref (spi_global_app_data->bus);
+ }
+
+ for (l = spi_global_app_data->direct_connections; l; l = l->next)
+ {
+ DBusConnection *connection;
+
+ connection = l->data;
+
+ droute_context_unregister (spi_global_app_data->droute, connection);
+ droute_unintercept_dbus (connection);
+ dbus_connection_unref (connection);
+ }
+ g_list_free (spi_global_app_data->direct_connections);
+
+ for (ls = clients; ls; ls = ls->next)
+ g_free (l->data);
+ g_slist_free (clients);
+ clients = NULL;
+
+ g_object_unref (spi_global_cache);
+ g_object_unref (spi_global_leasing);
+ g_object_unref (spi_global_register);
+
+ if (spi_global_app_data->main_context)
+ g_main_context_unref (spi_global_app_data->main_context);
+
+ droute_free (spi_global_app_data->droute);
+
+ g_free (spi_global_app_data);
+ spi_global_app_data = NULL;
+}
+