From 42a5cede3a440e11023b2e598cd04e2b0198a9c5 Mon Sep 17 00:00:00 2001 From: Leonid Evdokimov Date: Sat, 2 Feb 2008 01:48:19 +0600 Subject: [PATCH] Fixed handling EOF from client while connection is ongoing. --- redsocks.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/redsocks.c b/redsocks.c index 68c8a50..0d90cc8 100644 --- a/redsocks.c +++ b/redsocks.c @@ -437,10 +437,16 @@ static void redsocks_accept_client(int fd, short what, void *_arg) log_errno("bufferevent_new"); goto fail; } + client_fd = -1; list_add(&client->list, &self->clients); - // now it's safe to redsocks_drop_client + // enable reading to handle EOF from client + if (bufferevent_enable(client->client, EV_READ) != 0) { + log_errno("bufferevent_enable"); + goto fail; + } + if (self->relay_ss->connect_relay) self->relay_ss->connect_relay(client); else @@ -449,9 +455,7 @@ static void redsocks_accept_client(int fd, short what, void *_arg) fail: if (client) { - if (client->client) - bufferevent_free(client->client); - free(client); + redsocks_drop_client(client); } if (client_fd != -1) close(client_fd);