Mercurial > hg > nginx
comparison src/event/ngx_event_connect.c @ 4452:ed05b25a721f stable-1.0
Merge of r4422:
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 | Sun, 05 Feb 2012 20:06:50 +0000 |
parents | 4919fb357a5d |
children | 87faa6b818bc |
comparison
equal
deleted
inserted
replaced
4451:aaeb1b2dcbf3 | 4452:ed05b25a721f |
---|---|
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 |