]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
_dbus_loop_iterate: if a watch has been invalidated, skip it
authorSimon McVittie <simon.mcvittie@collabora.co.uk>
Wed, 12 Jan 2011 11:58:31 +0000 (11:58 +0000)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Fri, 21 Jan 2011 15:01:16 +0000 (15:01 +0000)
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 <walters@verbum.org>
dbus/dbus-mainloop.c

index 96ba599b0f07f863909f42485200c7a9f2a7dd69..2e1cf7e993aa1e56f91e3c8f7109adbf5fa50733 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <dbus/dbus-list.h>
 #include <dbus/dbus-sysdeps.h>
+#include <dbus/dbus-watch.h>
 
 #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;