[nginx] svn commit: r4422 - trunk/src/event

mdounin at mdounin.ru mdounin at mdounin.ru
Mon Jan 30 11:12:53 UTC 2012


Author: mdounin
Date: 2012-01-30 11:12:52 +0000 (Mon, 30 Jan 2012)
New Revision: 4422

Log:
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.


Modified:
   trunk/src/event/ngx_event_connect.c

Modified: trunk/src/event/ngx_event_connect.c
===================================================================
--- trunk/src/event/ngx_event_connect.c	2012-01-30 10:17:56 UTC (rev 4421)
+++ trunk/src/event/ngx_event_connect.c	2012-01-30 11:12:52 UTC (rev 4422)
@@ -160,6 +160,9 @@
             ngx_log_error(level, c->log, err, "connect() to %V failed",
                           pc->name);
 
+            ngx_close_connection(c);
+            pc->connection = NULL;
+
             return NGX_DECLINED;
         }
     }
@@ -241,13 +244,9 @@
 
 failed:
 
-    ngx_free_connection(c);
+    ngx_close_connection(c);
+    pc->connection = NULL;
 
-    if (ngx_close_socket(s) == -1) {
-        ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
-                      ngx_close_socket_n " failed");
-    }
-
     return NGX_ERROR;
 }
 



More information about the nginx-devel mailing list