Call event_debug_unassign on internal events

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.
This commit is contained in:
Nick Mathewson 2010-01-25 13:38:07 -05:00
parent cd17c3acd5
commit a19b4a05e6
6 changed files with 32 additions and 10 deletions

View File

@ -539,10 +539,14 @@ _bufferevent_decref_and_unlock(struct bufferevent *bufev)
bufferevent_remove_from_rate_limit_group(bufev); bufferevent_remove_from_rate_limit_group(bufev);
if (event_initialized(&bufev_private->rate_limiting->refill_bucket_event)) if (event_initialized(&bufev_private->rate_limiting->refill_bucket_event))
event_del(&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); mm_free(bufev_private->rate_limiting);
bufev_private->rate_limiting = NULL; bufev_private->rate_limiting = NULL;
} }
event_debug_unassign(&bufev->ev_read);
event_debug_unassign(&bufev->ev_write);
BEV_UNLOCK(bufev); BEV_UNLOCK(bufev);
if (bufev_private->own_lock) if (bufev_private->own_lock)
EVTHREAD_FREE_LOCK(bufev_private->lock, EVTHREAD_FREE_LOCK(bufev_private->lock,

22
evdns.c
View File

@ -2102,6 +2102,7 @@ server_port_free(struct evdns_server_port *port)
port->socket = -1; port->socket = -1;
} }
(void) event_del(&port->event); (void) event_del(&port->event);
event_debug_unassign(&port->event);
EVTHREAD_FREE_LOCK(port->lock, EVTHREAD_LOCKTYPE_RECURSIVE); EVTHREAD_FREE_LOCK(port->lock, EVTHREAD_LOCKTYPE_RECURSIVE);
mm_free(port); mm_free(port);
} }
@ -2490,6 +2491,7 @@ _evdns_nameserver_add_impl(struct evdns_base *base, const struct sockaddr *addre
out2: out2:
CLOSE_SOCKET(ns->socket); CLOSE_SOCKET(ns->socket);
out1: out1:
event_debug_unassign(&ns->event);
mm_free(ns); mm_free(ns);
log(EVDNS_LOG_WARN, "Unable to add nameserver %s: error %d", debug_ntop(address), err); log(EVDNS_LOG_WARN, "Unable to add nameserver %s: error %d", debug_ntop(address), err);
return 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 static void
evdns_base_free_and_unlock(struct evdns_base *base, int fail_requests) 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) { for (server = base->server_head; server; server = server_next) {
server_next = server->next; server_next = server->next;
if (server->socket >= 0) evdns_nameserver_free(server);
CLOSE_SOCKET(server->socket);
(void) event_del(&server->event);
if (server->state == 0)
(void) event_del(&server->timeout_event);
mm_free(server);
if (server_next == base->server_head) if (server_next == base->server_head)
break; break;
} }

View File

@ -612,6 +612,7 @@ event_base_free(struct event_base *base)
EVUTIL_CLOSESOCKET(base->th_notify_fd[1]); EVUTIL_CLOSESOCKET(base->th_notify_fd[1]);
base->th_notify_fd[0] = -1; base->th_notify_fd[0] = -1;
base->th_notify_fd[1] = -1; base->th_notify_fd[1] = -1;
event_debug_unassign(&base->th_notify);
} }
/* Delete all non-internal events. */ /* Delete all non-internal events. */
@ -631,6 +632,7 @@ event_base_free(struct event_base *base)
struct common_timeout_list *ctl = struct common_timeout_list *ctl =
base->common_timeout_queues[i]; base->common_timeout_queues[i];
event_del(&ctl->timeout_event); /* Internal; doesn't count */ event_del(&ctl->timeout_event); /* Internal; doesn't count */
event_debug_unassign(&ctl->timeout_event);
for (ev = TAILQ_FIRST(&ctl->events); ev; ) { for (ev = TAILQ_FIRST(&ctl->events); ev; ) {
struct event *next = TAILQ_NEXT(ev, struct event *next = TAILQ_NEXT(ev,
ev_timeout_pos.ev_next_with_common_timeout); 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; struct event_once *eonce = arg;
(*eonce->cb)(fd, events, eonce->arg); (*eonce->cb)(fd, events, eonce->arg);
event_debug_unassign(&eonce->ev);
mm_free(eonce); mm_free(eonce);
} }

5
http.c
View File

@ -953,8 +953,10 @@ evhttp_connection_free(struct evhttp_connection *evcon)
TAILQ_REMOVE(&http->connections, evcon, next); TAILQ_REMOVE(&http->connections, evcon, next);
} }
if (event_initialized(&evcon->retry_ev)) if (event_initialized(&evcon->retry_ev)) {
event_del(&evcon->retry_ev); event_del(&evcon->retry_ev);
event_debug_unassign(&evcon->retry_ev);
}
if (evcon->bufev != NULL) if (evcon->bufev != NULL)
bufferevent_free(evcon->bufev); 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); TAILQ_REMOVE(&http->sockets, bound, next);
event_del(&bound->bind_ev); event_del(&bound->bind_ev);
event_debug_unassign(&bound->bind_ev);
mm_free(bound); mm_free(bound);
} }

View File

@ -216,6 +216,7 @@ event_listener_destroy(struct evconnlistener *lev)
event_del(&lev_e->listener); event_del(&lev_e->listener);
if (lev->flags & LEV_OPT_CLOSE_ON_FREE) if (lev->flags & LEV_OPT_CLOSE_ON_FREE)
EVUTIL_CLOSESOCKET(event_get_fd(&lev_e->listener)); EVUTIL_CLOSESOCKET(event_get_fd(&lev_e->listener));
event_debug_unassign(&lev_e->listener);
} }
int int

View File

@ -318,6 +318,7 @@ evsig_dealloc(struct event_base *base)
int i = 0; int i = 0;
if (base->sig.ev_signal_added) { if (base->sig.ev_signal_added) {
event_del(&base->sig.ev_signal); event_del(&base->sig.ev_signal);
event_debug_unassign(&base->sig.ev_signal);
base->sig.ev_signal_added = 0; base->sig.ev_signal_added = 0;
} }
for (i = 0; i < NSIG; ++i) { for (i = 0; i < NSIG; ++i) {