Index: glib/dbus-gobject.c =================================================================== RCS file: /cvs/dbus/dbus/glib/dbus-gobject.c,v retrieving revision 1.21 diff -u -r1.21 dbus-gobject.c --- glib/dbus-gobject.c 27 Feb 2005 17:38:12 -0000 1.21 +++ glib/dbus-gobject.c 29 Apr 2005 16:33:43 -0000 @@ -1048,6 +1048,22 @@ g_static_rw_lock_writer_unlock (&info_hash_lock); } +static GQuark +object_path_quark (void) +{ + static GQuark quark = 0; + if (!quark) + quark = g_quark_from_static_string ("dbus_glib_object_path"); + return quark; +} + +static void +unregister_gobject(DBusGConnection *connection, GObject *dead) +{ + dbus_connection_unregister_object_path (DBUS_CONNECTION_FROM_G_CONNECTION (connection), + g_object_get_qdata (dead, object_path_quark ())); +} + /** * Registers a GObject at the given path. Properties, methods, and signals * of the object can then be accessed remotely. Methods are only available @@ -1073,12 +1089,13 @@ if (!dbus_connection_register_object_path (DBUS_CONNECTION_FROM_G_CONNECTION (connection), at_path, &gobject_dbus_vtable, - object)) + object)) { g_error ("Failed to register GObject with DBusConnection"); + return; + } - /* FIXME set up memory management (so we break the - * registration if object or connection vanishes) - */ + g_object_set_qdata (object, object_path_quark (), g_strdup (at_path)); + g_object_weak_ref (object, (GWeakNotify)unregister_gobject, connection); } /** @} */ /* end of public API */