From: Simon McVittie Date: Wed, 12 Jan 2011 11:58:31 +0000 (+0000) Subject: _dbus_loop_iterate: if a watch has been invalidated, skip it X-Git-Tag: dbus-1.4.4~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f740396874466cb6ea40af717d636d381c1c4feb;p=thirdparty%2Fdbus.git _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. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=32992 Bug-NB: NB#200248 Reviewed-by: Colin Walters --- diff --git a/dbus/dbus-mainloop.c b/dbus/dbus-mainloop.c index 96ba599b0..2e1cf7e99 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;