From 89d422914a0c3cbba5e3827248f97c536ce69de5 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 9 Feb 2005 23:16:31 +0000 Subject: Patch from adam langley: always remove sockets from libevent before closing them. Should fix epoll-related bugs. svn:r3606 --- src/or/connection.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/or/connection.c b/src/or/connection.c index cf42edba81..dccbfc6771 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -163,10 +163,6 @@ _connection_free(connection_t *conn) { tor_free(conn->nickname); tor_free(conn->socks_request); - if (conn->s >= 0) { - log_fn(LOG_INFO,"closing fd %d.",conn->s); - tor_close_socket(conn->s); - } if (conn->read_event) { event_del(conn->read_event); tor_free(conn->read_event); @@ -175,6 +171,11 @@ _connection_free(connection_t *conn) { event_del(conn->write_event); tor_free(conn->write_event); } + if (conn->s >= 0) { + log_fn(LOG_INFO,"closing fd %d.",conn->s); + tor_close_socket(conn->s); + } + memset(conn, 0xAA, sizeof(connection_t)); /* poison memory */ tor_free(conn); } @@ -309,6 +310,16 @@ void connection_close_immediate(connection_t *conn) conn->s, CONN_TYPE_TO_STRING(conn->type), conn->state, (int)conn->outbuf_flushlen); } + if (conn->read_event) { + event_del(conn->read_event); + tor_free(conn->read_event); + conn->read_event = NULL; + } + if (conn->write_event) { + event_del(conn->write_event); + tor_free(conn->write_event); + conn->write_event = NULL; + } tor_close_socket(conn->s); conn->s = -1; if (!connection_is_listener(conn)) { -- cgit v1.2.3-54-g00ecf