[patch] do not segfault when D-Bus connection is reused

Timo Hoenig thoenig at suse.de
Thu Aug 24 04:12:50 PDT 2006


Hi,

With D-Bus 0.9x all applications which run code like [1] segfault.  This
was introduced by keeping a hard reference to the D-Bus connection [2].

The problem is that dbus_bus_get() now bumps the reference count twice
while it is decremented only once -- by the applications themselves.

The attached patch makes dbus_bus_close() call
_dbus_bus_check_connection_and_unref() which decrements the
corresponding reference count of the hard reference.

Please review.

Thanks,

   Timo


[1] Test case

    void h (void)
    {
        DBusConnection *conn;

        conn = dbus_bus_get (DBUS_BUS_SYSTEM, NULL);
        /* call some D-Bus function(s) */
        dbus_connection_close (conn);
        dbus_connection_unref (conn);
    }

    int main (int argc, char *argv[])
    {
        h ();
        h ();
    }

[2] Keeping a hard reference to the D-Bus Connection
    http://webcvs.freedesktop.org/dbus/dbus/dbus/dbus-bus.c?r1=1.50&r2=1.51&view=patch
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dbus-unref-connections-on-close-thoenig-01.patch
Type: text/x-patch
Size: 631 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/dbus/attachments/20060824/5672a6b0/dbus-unref-connections-on-close-thoenig-01.bin


More information about the dbus mailing list