Unconditionally remove timeouts from the queue before calling the callback.
[tinc] / src / event.c
index 84b18b3..33d205a 100644 (file)
@@ -41,12 +41,15 @@ static int io_compare(const io_t *a, const io_t *b) {
 #ifndef HAVE_MINGW
        return a->fd - b->fd;
 #else
+
        if(a->event < b->event) {
                return -1;
        }
+
        if(a->event > b->event) {
                return 1;
        }
+
        return 0;
 #endif
 }
@@ -297,11 +300,9 @@ static struct timeval *get_time_remaining(struct timeval *diff) {
                timersub(&timeout->tv, &now, diff);
 
                if(diff->tv_sec < 0) {
-                       timeout->cb(timeout->data);
-
-                       if(timercmp(&timeout->tv, &now, <)) {
-                               timeout_del(timeout);
-                       }
+                       timeout_cb_t cb = timeout->cb;
+                       timeout_del(timeout);
+                       cb(timeout->data);
                } else {
                        tv = diff;
                        break;