dbus cleanup question

Havoc Pennington hp at pobox.com
Tue Feb 19 04:49:32 PST 2008


On Feb 19, 2008 7:06 AM, Macartney, Geoff <gmacartney at tycoint.com> wrote:
> I'm using the low level API to dbus (working on an embedded platform). What
> cleanup do I need to do when shutting down, to prevent any resource leaks?
> My programs open a connection to the system bus, and I'm assuming I need to
> call dbus_connection_unref on the connection when I'm done with it. But what
> about the following?

unref anything you have a ref to and dbus_shutdown() generally. (If
your program is not exiting. If your app is exiting, just exit,
dbus_shutdown() is pointless.)

> If I've added matches to the connection using dbus_bus_add_match, do I need
> to explicitly remove them with dbus_bus_remove_match before I unref the
> connection?

No, because this resource (the match) is in the bus daemon, and the
daemon will free it when you disconnect.

> If I've added handlers for object paths using
> dbus_connection_register_fallback or dbus_connection_register_object_path,
> do I need to remove them using dbus_connection_unregister_object_path before
> I unref the connection?

If the connection is finalized (refcount reaches 0) your object path
is automatically unregistered. However, typically it's better to
unregister an object path at the point where you don't want it invoked
anymore; after all, someone else may be holding a refcount, and you
don't want the object path registration to accidentally stay alive,
especially if you freed the object it refers to.


More information about the dbus mailing list