Klaus Demo nginx / 4a23bc5
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. Maxim Dounin 10 years ago
1 changed file(s) with 5 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
159159 ngx_log_error(level, c->log, err, "connect() to %V failed",
160160 pc->name);
161161
162 ngx_close_connection(c);
163 pc->connection = NULL;
164
162165 return NGX_DECLINED;
163166 }
164167 }
240243
241244 failed:
242245
243 ngx_free_connection(c);
244
245 if (ngx_close_socket(s) == -1) {
246 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
247 ngx_close_socket_n " failed");
248 }
246 ngx_close_connection(c);
247 pc->connection = NULL;
249248
250249 return NGX_ERROR;
251250 }