]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virdbus: Grab a ref as long as the while loop is executed
authorMarc Hartmayer <mhartmay@linux.vnet.ibm.com>
Fri, 21 Sep 2018 13:02:01 +0000 (15:02 +0200)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 25 Sep 2018 23:27:21 +0000 (19:27 -0400)
Grab a ref for info->bus (a DBus connection) as long as the while loop
is running. With the grabbed reference it is ensured that info->bus
isn't freed as long as the while loop is executed. This is necessary
as it's allowed to drop the last ref for the bus connection in a
handler.

There was already a bug of this kind in libdbus itself:
https://bugs.freedesktop.org/show_bug.cgi?id=15635.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/util/virdbus.c

index 05b1f6c345be16db4c97f19874e63b89ec2251a6..0aa0fc6ee036353e385eac8b01a0a6b20ca7eec7 100644 (file)
@@ -198,8 +198,10 @@ static void virDBusWatchCallback(int fdatch ATTRIBUTE_UNUSED,
 
     (void)dbus_watch_handle(watch, dbus_flags);
 
+    dbus_connection_ref(info->bus);
     while (dbus_connection_dispatch(info->bus) == DBUS_DISPATCH_DATA_REMAINS)
         /* keep dispatching while data remains */;
+    dbus_connection_unref(info->bus);
 }