# HG changeset patch # User Maxim Dounin # Date 1327921972 0 # Node ID fbae1a82de8b4e821b34859bff08fbbabf90a0fe # Parent 9ce48f9eb85b8e301366916af78c0d6aaa4d2e01 Fixed error handling in ngx_event_connect_peer(). Previously if ngx_add_event() failed a connection was freed two times (once in the ngx_event_connect_peer(), and again by a caller) as pc->connection was left set. Fix is to always use ngx_close_connection() to close connection properly and set pc->connection to NULL on errors. Patch by Piotr Sikora. diff --git a/src/event/ngx_event_connect.c b/src/event/ngx_event_connect.c --- a/src/event/ngx_event_connect.c +++ b/src/event/ngx_event_connect.c @@ -160,6 +160,9 @@ ngx_event_connect_peer(ngx_peer_connecti ngx_log_error(level, c->log, err, "connect() to %V failed", pc->name); + ngx_close_connection(c); + pc->connection = NULL; + return NGX_DECLINED; } } @@ -241,12 +244,8 @@ ngx_event_connect_peer(ngx_peer_connecti failed: - ngx_free_connection(c); - - if (ngx_close_socket(s) == -1) { - ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno, - ngx_close_socket_n " failed"); - } + ngx_close_connection(c); + pc->connection = NULL; return NGX_ERROR; }