Fix race leading to crash when setting up dbus watches

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>
(cherry picked from commit 7d3a1c8bd1)
This commit is contained in:
Daniel P. Berrange 2013-12-18 12:19:46 +00:00 committed by Cole Robinson
parent 51afa9a255
commit 3ba6892066

View File

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