]> xenbits.xensource.com Git - people/dariof/libvirt.git/commitdiff
Fix race leading to crash when setting up dbus watches
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 18 Dec 2013 12:19:46 +0000 (12:19 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 18 Dec 2013 16:59:02 +0000 (16:59 +0000)
Currently the virDBusAddWatch does

  virEventAddHandle(fd, flags,
                    virDBusWatchCallback,
                    watch, NULL);
  dbus_watch_set_data(watch, info, virDBusWatchFree);

Unfortunately this is racy - since the event loop is in a
different thread, the virDBusWatchCallback method may be
run before we get to calling dbus_watch_set_data. We must
reverse the order of these calls

See https://bugzilla.redhat.com/show_bug.cgi?id=885445

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/util/virdbus.c

index 4e4c267126839e38c1258e11d10fa377e235d938..a0cbbfe2182b595e3f2d6f61e2ce206d4b0dbd2d 100644 (file)
@@ -238,15 +238,15 @@ static dbus_bool_t virDBusAddWatch(DBusWatch *watch,
 # else
     fd = dbus_watch_get_fd(watch);
 # endif
+    dbus_watch_set_data(watch, info, virDBusWatchFree);
     info->bus = (DBusConnection *)data;
     info->watch = virEventAddHandle(fd, flags,
                                     virDBusWatchCallback,
                                     watch, NULL);
     if (info->watch < 0) {
-        VIR_FREE(info);
+        dbus_watch_set_data(watch, NULL, NULL);
         return 0;
     }
-    dbus_watch_set_data(watch, info, virDBusWatchFree);
 
     return 1;
 }