From 7d3a1c8bd1a2d376dfb5d7ee6a1bca8772ec2949 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Wed, 18 Dec 2013 12:19:46 +0000 Subject: [PATCH] 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 --- src/util/virdbus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/virdbus.c b/src/util/virdbus.c index 4e4c267126..a0cbbfe218 100644 --- a/src/util/virdbus.c +++ b/src/util/virdbus.c @@ -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; } -- GitLab