]> granicus.if.org Git - libevent/commitdiff
Call event_debug_unassign on internal events
authorNick Mathewson <nickm@torproject.org>
Mon, 25 Jan 2010 18:38:07 +0000 (13:38 -0500)
committerNick Mathewson <nickm@torproject.org>
Mon, 25 Jan 2010 18:53:17 +0000 (13:53 -0500)
I don't expect that many users will be so religious about calling
unassign, but we need to be so that it's at least possible to use
debug mode without eating memory.

bufferevent.c
evdns.c
event.c
http.c
listener.c
signal.c

index 77f18240ca3e2b5e7e06dd02f71e32fb31e419f2..b27345042db8d4fa7bb3b51e51f0608ab717c258 100644 (file)
@@ -539,10 +539,14 @@ _bufferevent_decref_and_unlock(struct bufferevent *bufev)
                        bufferevent_remove_from_rate_limit_group(bufev);
                if (event_initialized(&bufev_private->rate_limiting->refill_bucket_event))
                        event_del(&bufev_private->rate_limiting->refill_bucket_event);
+               event_debug_unassign(&bufev_private->rate_limiting->refill_bucket_event);
                mm_free(bufev_private->rate_limiting);
                bufev_private->rate_limiting = NULL;
        }
 
+       event_debug_unassign(&bufev->ev_read);
+       event_debug_unassign(&bufev->ev_write);
+
        BEV_UNLOCK(bufev);
        if (bufev_private->own_lock)
                EVTHREAD_FREE_LOCK(bufev_private->lock,
diff --git a/evdns.c b/evdns.c
index 924e5e4512682fb9d92c6e7875230bc7f1fdeba4..29ea5432a0c3ba88ab15adeffcf9205c95ba74b8 100644 (file)
--- a/evdns.c
+++ b/evdns.c
@@ -2102,6 +2102,7 @@ server_port_free(struct evdns_server_port *port)
                port->socket = -1;
        }
        (void) event_del(&port->event);
+       event_debug_unassign(&port->event);
        EVTHREAD_FREE_LOCK(port->lock, EVTHREAD_LOCKTYPE_RECURSIVE);
        mm_free(port);
 }
@@ -2490,6 +2491,7 @@ _evdns_nameserver_add_impl(struct evdns_base *base, const struct sockaddr *addre
 out2:
        CLOSE_SOCKET(ns->socket);
 out1:
+       event_debug_unassign(&ns->event);
        mm_free(ns);
        log(EVDNS_LOG_WARN, "Unable to add nameserver %s: error %d", debug_ntop(address), err);
        return err;
@@ -3799,6 +3801,19 @@ evdns_err_to_string(int err)
     }
 }
 
+static void
+evdns_nameserver_free(struct nameserver *server)
+{
+       if (server->socket >= 0)
+       CLOSE_SOCKET(server->socket);
+       (void) event_del(&server->event);
+       event_debug_unassign(&server->event);
+       if (server->state == 0)
+               (void) event_del(&server->timeout_event);
+       event_debug_unassign(&server->timeout_event);
+       mm_free(server);
+}
+
 static void
 evdns_base_free_and_unlock(struct evdns_base *base, int fail_requests)
 {
@@ -3826,12 +3841,7 @@ evdns_base_free_and_unlock(struct evdns_base *base, int fail_requests)
 
        for (server = base->server_head; server; server = server_next) {
                server_next = server->next;
-               if (server->socket >= 0)
-                       CLOSE_SOCKET(server->socket);
-               (void) event_del(&server->event);
-               if (server->state == 0)
-                       (void) event_del(&server->timeout_event);
-               mm_free(server);
+               evdns_nameserver_free(server);
                if (server_next == base->server_head)
                        break;
        }
diff --git a/event.c b/event.c
index d12b72e758546dbb205dcb82448a3b55701492b7..f4c6fc72437166195e9788b56b229fd0b10329cc 100644 (file)
--- a/event.c
+++ b/event.c
@@ -612,6 +612,7 @@ event_base_free(struct event_base *base)
                EVUTIL_CLOSESOCKET(base->th_notify_fd[1]);
                base->th_notify_fd[0] = -1;
                base->th_notify_fd[1] = -1;
+               event_debug_unassign(&base->th_notify);
        }
 
        /* Delete all non-internal events. */
@@ -631,6 +632,7 @@ event_base_free(struct event_base *base)
                struct common_timeout_list *ctl =
                    base->common_timeout_queues[i];
                event_del(&ctl->timeout_event); /* Internal; doesn't count */
+               event_debug_unassign(&ctl->timeout_event);
                for (ev = TAILQ_FIRST(&ctl->events); ev; ) {
                        struct event *next = TAILQ_NEXT(ev,
                            ev_timeout_pos.ev_next_with_common_timeout);
@@ -1397,6 +1399,7 @@ event_once_cb(evutil_socket_t fd, short events, void *arg)
        struct event_once *eonce = arg;
 
        (*eonce->cb)(fd, events, eonce->arg);
+       event_debug_unassign(&eonce->ev);
        mm_free(eonce);
 }
 
diff --git a/http.c b/http.c
index 2e32d9e59e4fb97106e9eb3929c7c9365163eecb..642816235051c8b1a57fa056ce234ade5826ae36 100644 (file)
--- a/http.c
+++ b/http.c
@@ -953,8 +953,10 @@ evhttp_connection_free(struct evhttp_connection *evcon)
                TAILQ_REMOVE(&http->connections, evcon, next);
        }
 
-       if (event_initialized(&evcon->retry_ev))
+       if (event_initialized(&evcon->retry_ev)) {
                event_del(&evcon->retry_ev);
+               event_debug_unassign(&evcon->retry_ev);
+       }
 
        if (evcon->bufev != NULL)
                bufferevent_free(evcon->bufev);
@@ -2555,6 +2557,7 @@ evhttp_del_accept_socket(struct evhttp *http, struct evhttp_bound_socket *bound)
 {
        TAILQ_REMOVE(&http->sockets, bound, next);
        event_del(&bound->bind_ev);
+       event_debug_unassign(&bound->bind_ev);
        mm_free(bound);
 }
 
index 31f5c89acfc3441f23028a9c7229ef5761d11d2a..fb60ef3f90823063f1172edcb999b6902f0e0a1d 100644 (file)
@@ -137,7 +137,7 @@ evconnlistener_new(struct event_base *base,
        lev = mm_calloc(1, sizeof(struct evconnlistener_event));
        if (!lev)
                return NULL;
-       
+
        lev->base.ops = &evconnlistener_event_ops;
        lev->base.cb = cb;
        lev->base.user_data = ptr;
@@ -146,7 +146,7 @@ evconnlistener_new(struct event_base *base,
        event_assign(&lev->listener, base, fd, EV_READ|EV_PERSIST,
            listener_read_cb, lev);
        evconnlistener_enable(&lev->base);
-       
+
        return &lev->base;
 }
 
@@ -212,10 +212,11 @@ event_listener_destroy(struct evconnlistener *lev)
 {
        struct evconnlistener_event *lev_e =
            EVUTIL_UPCAST(lev, struct evconnlistener_event, base);
-       
+
        event_del(&lev_e->listener);
        if (lev->flags & LEV_OPT_CLOSE_ON_FREE)
                EVUTIL_CLOSESOCKET(event_get_fd(&lev_e->listener));
+       event_debug_unassign(&lev_e->listener);
 }
 
 int
index 7c8e09acf5647f8edce17416bf3276c461138cb8..dfc908dd5eb91b03f178531327b3c8f3c53fa502 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -318,6 +318,7 @@ evsig_dealloc(struct event_base *base)
        int i = 0;
        if (base->sig.ev_signal_added) {
                event_del(&base->sig.ev_signal);
+               event_debug_unassign(&base->sig.ev_signal);
                base->sig.ev_signal_added = 0;
        }
        for (i = 0; i < NSIG; ++i) {