From 0d31ee28ead95123848ccd04266e5ff62b7867a0 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 12 Jan 2011 11:58:31 +0000 Subject: [PATCH 2/4] _dbus_loop_iterate: if a watch has been invalidated, skip it This shouldn't happen - other modules are responsible for cleaning up their watches - but the bug fixed in my last commit has been present for several years and I'm sure it's not the only one, so for robustness, let's refuse to watch obviously-wrong file descriptors. Related to --- dbus/dbus-mainloop.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/dbus/dbus-mainloop.c b/dbus/dbus-mainloop.c index 96ba599..2e1cf7e 100644 --- a/dbus/dbus-mainloop.c +++ b/dbus/dbus-mainloop.c @@ -28,6 +28,7 @@ #include #include +#include #define MAINLOOP_SPEW 0 @@ -584,6 +585,7 @@ _dbus_loop_iterate (DBusLoop *loop, { unsigned int flags; WatchCallback *wcb = WATCH_CALLBACK (cb); + int fd = dbus_watch_get_socket (wcb->watch); if (wcb->last_iteration_oom) { @@ -602,6 +604,13 @@ _dbus_loop_iterate (DBusLoop *loop, dbus_watch_get_socket (wcb->watch)); #endif } + else if (_DBUS_UNLIKELY (fd == -1)) + { + _dbus_warn ("watch %p was invalidated but not removed; " + "removing it now\n", wcb->watch); + _dbus_loop_remove_watch (loop, wcb->watch, wcb->function, + ((Callback *)wcb)->data); + } else if (dbus_watch_get_enabled (wcb->watch)) { watches_for_fds[n_fds] = wcb; -- 1.7.2.3