Skip to content

Commit

Permalink
Fix cleanup order to avoid EBADF from epoll_ctl
Browse files Browse the repository at this point in the history
  • Loading branch information
darkk committed Apr 13, 2016
1 parent 7963de7 commit 83702c9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions redsocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,23 +749,28 @@ void redsocks_drop_client(redsocks_client *client)
redsocks_close(pump->reply.write);

// redsocks_close MAY log error if some of events was not properly initialized
int fd = -1;
if (event_initialized(&pump->client_read)) {
int fd = event_get_fd(&pump->client_read);
fd = event_get_fd(&pump->client_read);
redsocks_event_del(&pump->c, &pump->client_read);
redsocks_close(fd);
}
if (event_initialized(&pump->client_write)) {
redsocks_event_del(&pump->c, &pump->client_write);
}
if (fd != -1)
redsocks_close(fd);

fd = -1;
if (event_initialized(&pump->relay_read)) {
int fd = event_get_fd(&pump->relay_read);
fd = event_get_fd(&pump->relay_read);
redsocks_event_del(&pump->c, &pump->relay_read);
redsocks_close(fd);
}
if (event_initialized(&pump->relay_write)) {
redsocks_event_del(&pump->c, &pump->relay_write);
}
if (fd != -1) {
redsocks_close(fd);
}
}

list_del(&client->list);
Expand Down

0 comments on commit 83702c9

Please sign in to comment.