]> granicus.if.org Git - libevent/commitdiff
remove pending timeouts on event_base_free
authorNiels Provos <provos@gmail.com>
Sat, 26 Jan 2008 07:29:57 +0000 (07:29 +0000)
committerNiels Provos <provos@gmail.com>
Sat, 26 Jan 2008 07:29:57 +0000 (07:29 +0000)
svn:r627

ChangeLog
event.c
test/regress.c

index 6e08592d10431aa305a92f6884b6e754f0d3b93f..acf951b04285ac82e9200ae11c3372832bf53c5b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -34,6 +34,7 @@ Changes in current version:
  o allow an http request callback to take ownership of a request structure
  o allow association of meta data with RPC requests for hook processing
  o associate more context for hooks to query such as the connection object
+ o remove pending timeouts on event_base_free()
        
 Changes in 1.4.0:
  o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.
diff --git a/event.c b/event.c
index 9b54cfcc1bb54fa7f6d4b0fe582e482a858bdb7d..791784326f43b5560bf6a04f2cc4893b24e00f0d 100644 (file)
--- a/event.c
+++ b/event.c
@@ -229,6 +229,11 @@ event_base_free(struct event_base *base)
                }
                ev = next;
        }
+       while ((ev = min_heap_top(&base->timeheap)) != NULL) {
+               event_del(ev);
+               ++n_deleted;
+       }
+
        if (n_deleted)
                event_debug(("%s: %d events were still set in base",
                                         __func__, n_deleted));
@@ -236,8 +241,9 @@ event_base_free(struct event_base *base)
        if (base->evsel->dealloc != NULL)
                base->evsel->dealloc(base, base->evbase);
 
-       for (i=0; i < base->nactivequeues; ++i)
+       for (i = 0; i < base->nactivequeues; ++i)
                assert(TAILQ_EMPTY(base->activequeues[i]));
+
        assert(min_heap_empty(&base->timeheap));
        min_heap_dtor(&base->timeheap);
 
index 11f621357c3099908398701d95e543023872cf79..a21670bd9309a671eb5fb883512b4bd31c20d185 100644 (file)
@@ -773,6 +773,33 @@ test_loopexit(void)
        cleanup_test();
 }
 
+static void
+test_loopexit_multiple(void)
+{
+       struct timeval tv;
+       struct event_base *base;
+
+       setup_test("Loop Multiple exit: ");
+
+       base = event_base_new();
+       
+       tv.tv_usec = 0;
+       tv.tv_sec = 1;
+       event_base_loopexit(base, &tv);
+
+       tv.tv_usec = 0;
+       tv.tv_sec = 2;
+       event_base_loopexit(base, &tv);
+
+       event_base_dispatch(base);
+
+       event_base_free(base);
+       
+       test_ok = 1;
+
+       cleanup_test();
+}
+
 static void
 break_cb(int fd, short events, void *arg)
 {
@@ -1603,6 +1630,8 @@ main (int argc, char **argv)
        test_loopexit();
        test_loopbreak();
 
+       test_loopexit_multiple();
+
         test_nonpersist_readd();
 
        test_multiple_events_for_same_fd();