comparison src/event/ngx_event_connect.c @ 4421:fbae1a82de8b

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.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 30 Jan 2012 11:12:52 +0000
parents d620f497c50f
children 87faa6b818bc
comparison
equal deleted inserted replaced
4420:9ce48f9eb85b 4421:fbae1a82de8b
158 } 158 }
159 159
160 ngx_log_error(level, c->log, err, "connect() to %V failed", 160 ngx_log_error(level, c->log, err, "connect() to %V failed",
161 pc->name); 161 pc->name);
162 162
163 ngx_close_connection(c);
164 pc->connection = NULL;
165
163 return NGX_DECLINED; 166 return NGX_DECLINED;
164 } 167 }
165 } 168 }
166 169
167 if (ngx_add_conn) { 170 if (ngx_add_conn) {
239 242
240 return NGX_OK; 243 return NGX_OK;
241 244
242 failed: 245 failed:
243 246
244 ngx_free_connection(c); 247 ngx_close_connection(c);
245 248 pc->connection = NULL;
246 if (ngx_close_socket(s) == -1) {
247 ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
248 ngx_close_socket_n " failed");
249 }
250 249
251 return NGX_ERROR; 250 return NGX_ERROR;
252 } 251 }
253 252
254 253