dbus_bus_get refcounting

Havoc Pennington hp at redhat.com
Sat May 20 18:49:14 PDT 2006


Hi,

I may be missing something since this seems like an obvious bug:
dbus_bus_get() docs claim it returns a reference. However, you can't 
possibly call unref() because you can only call unref() on a connection 
if you either a) know it's been disconnected or b) know you don't have 
the only outstanding ref to it. For dbus_bus_get() these are more or 
less impossible right now.

The obvious simple hello world prints warnings:
  connection = dbus_bus_get();
  /* do stuff */
  dbus_connection_unref(connection);

NetworkManager seems to have as a workaround only unref'ing on the 
disconnect message...

Obviously I messed this up in the first place but it seems pretty lame 
to me now.

I think the right fix is to leave dbus_bus_get() returning a ref, but 
have it also hold a strong ref internally instead of a weak ref. Then 
you can know it's safe to unref this connection since the 
internal-to-dbus strong ref is held until it's disconnected.

Havoc


More information about the dbus mailing list