Blame 0040-dbus-first-restart-timer-then-dispatch-it.patch

f65aa27
From 96592c21150e789156153dcebd14e201cd41cbeb Mon Sep 17 00:00:00 2001
f65aa27
From: Lennart Poettering <lennart@poettering.net>
f65aa27
Date: Tue, 16 Feb 2010 02:49:44 +0100
f65aa27
Subject: [PATCH 40/62] dbus: first restart timer, then dispatch it
f65aa27
f65aa27
This makes sure that we don't access the timer after it might have been
f65aa27
destroyed already from the dbus timeout callback.
f65aa27
f65aa27
https://bugzilla.redhat.com/attachment.cgi?id=389952
f65aa27
---
f65aa27
 src/pulsecore/dbus-util.c |   29 ++++++++++++++++-------------
f65aa27
 1 files changed, 16 insertions(+), 13 deletions(-)
f65aa27
f65aa27
diff --git a/src/pulsecore/dbus-util.c b/src/pulsecore/dbus-util.c
f65aa27
index 4e6148f..40b64a0 100644
f65aa27
--- a/src/pulsecore/dbus-util.c
f65aa27
+++ b/src/pulsecore/dbus-util.c
f65aa27
@@ -44,17 +44,16 @@ struct pa_dbus_wrap_connection {
f65aa27
 };
f65aa27
 
f65aa27
 struct timeout_data {
f65aa27
-    pa_dbus_wrap_connection *c;
f65aa27
+    pa_dbus_wrap_connection *connection;
f65aa27
     DBusTimeout *timeout;
f65aa27
 };
f65aa27
 
f65aa27
 static void dispatch_cb(pa_mainloop_api *ea, pa_defer_event *ev, void *userdata) {
f65aa27
     DBusConnection *conn = userdata;
f65aa27
 
f65aa27
-    if (dbus_connection_dispatch(conn) == DBUS_DISPATCH_COMPLETE) {
f65aa27
+    if (dbus_connection_dispatch(conn) == DBUS_DISPATCH_COMPLETE)
f65aa27
         /* no more data to process, disable the deferred */
f65aa27
         ea->defer_enable(ev, 0);
f65aa27
-    }
f65aa27
 }
f65aa27
 
f65aa27
 /* DBusDispatchStatusFunction callback for the pa mainloop */
f65aa27
@@ -131,13 +130,17 @@ static void handle_time_event(pa_mainloop_api *ea, pa_time_event* e, const struc
f65aa27
     struct timeout_data *d = userdata;
f65aa27
 
f65aa27
     pa_assert(d);
f65aa27
-    pa_assert(d->c);
f65aa27
+    pa_assert(d->connection);
f65aa27
 
f65aa27
     if (dbus_timeout_get_enabled(d->timeout)) {
f65aa27
-        dbus_timeout_handle(d->timeout);
f65aa27
+        /* Restart it for the next scheduled time. We do this before
f65aa27
+         * calling dbus_timeout_handle() to make sure that the time
f65aa27
+         * event is still around. */
f65aa27
+        ea->time_restart(e, pa_timeval_rtstore(&tv,
f65aa27
+                                               pa_timeval_load(t) + dbus_timeout_get_interval(d->timeout) * PA_USEC_PER_MSEC,
f65aa27
+                                               d->connection->use_rtclock));
f65aa27
 
f65aa27
-        /* restart it for the next scheduled time */
f65aa27
-        ea->time_restart(e, pa_timeval_rtstore(&tv, pa_timeval_load(t) + dbus_timeout_get_interval(d->timeout) * PA_USEC_PER_MSEC, d->c->use_rtclock));
f65aa27
+        dbus_timeout_handle(d->timeout);
f65aa27
     }
f65aa27
 }
f65aa27
 
f65aa27
@@ -207,7 +210,7 @@ static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data) {
f65aa27
         return FALSE;
f65aa27
 
f65aa27
     d = pa_xnew(struct timeout_data, 1);
f65aa27
-    d->c = c;
f65aa27
+    d->connection = c;
f65aa27
     d->timeout = timeout;
f65aa27
     ev = c->mainloop->time_new(c->mainloop, pa_timeval_rtstore(&tv, pa_rtclock_now() + dbus_timeout_get_interval(timeout) * PA_USEC_PER_MSEC, c->use_rtclock), handle_time_event, d);
f65aa27
     c->mainloop->time_set_destroy(ev, time_event_destroy_cb);
f65aa27
@@ -236,15 +239,15 @@ static void toggle_timeout(DBusTimeout *timeout, void *data) {
f65aa27
     struct timeval tv;
f65aa27
 
f65aa27
     pa_assert(d);
f65aa27
-    pa_assert(d->c);
f65aa27
+    pa_assert(d->connection);
f65aa27
     pa_assert(timeout);
f65aa27
 
f65aa27
     pa_assert_se(ev = dbus_timeout_get_data(timeout));
f65aa27
 
f65aa27
-    if (dbus_timeout_get_enabled(timeout)) {
f65aa27
-        d->c->mainloop->time_restart(ev, pa_timeval_rtstore(&tv, pa_rtclock_now() + dbus_timeout_get_interval(timeout) * PA_USEC_PER_MSEC, d->c->use_rtclock));
f65aa27
-    } else
f65aa27
-        d->c->mainloop->time_restart(ev, pa_timeval_rtstore(&tv, PA_USEC_INVALID, d->c->use_rtclock));
f65aa27
+    if (dbus_timeout_get_enabled(timeout))
f65aa27
+        d->connection->mainloop->time_restart(ev, pa_timeval_rtstore(&tv, pa_rtclock_now() + dbus_timeout_get_interval(timeout) * PA_USEC_PER_MSEC, d->connection->use_rtclock));
f65aa27
+    else
f65aa27
+        d->connection->mainloop->time_restart(ev, pa_timeval_rtstore(&tv, PA_USEC_INVALID, d->connection->use_rtclock));
f65aa27
 }
f65aa27
 
f65aa27
 static void wakeup_main(void *userdata) {
f65aa27
-- 
f65aa27
1.7.0
f65aa27