diff options
author | Maxim Dounin <mdounin@mdounin.ru> | 2012-02-05 20:06:50 +0000 |
---|---|---|
committer | Maxim Dounin <mdounin@mdounin.ru> | 2012-02-05 20:06:50 +0000 |
commit | b39bc1ccbddbcd1a3f0d3972c2ab04762b2d580d (patch) | |
tree | 59c446e603b449bfdaeda66a75fc24722e9e041e | |
parent | f4d00a96acd56fb0d41233f5f1346f051528129a (diff) | |
download | nginx-b39bc1ccbddbcd1a3f0d3972c2ab04762b2d580d.tar.gz nginx-b39bc1ccbddbcd1a3f0d3972c2ab04762b2d580d.zip |
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.
-rw-r--r-- | src/event/ngx_event_connect.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/event/ngx_event_connect.c b/src/event/ngx_event_connect.c index d501b2e53..978f39b42 100644 --- a/src/event/ngx_event_connect.c +++ b/src/event/ngx_event_connect.c @@ -160,6 +160,9 @@ ngx_event_connect_peer(ngx_peer_connection_t *pc) 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_connection_t *pc) 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; } |