about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2011-06-05 15:00:32 +0200
committerFlorian Westphal <fw@strlen.de>2011-06-05 15:00:32 +0200
commit42b32f8a2adcbe0d7b011083cc0549ae89139449 (patch)
tree385e50a5320677c7429773e90dade2e3d010a306
parent49b2d0ec98d001fbc8eedd5a183d66974f70fd52 (diff)
downloadngircd-42b32f8a2adcbe0d7b011083cc0549ae89139449.tar.gz
ngircd-42b32f8a2adcbe0d7b011083cc0549ae89139449.zip
conn: fix error handling when connecting to server
The io_event_create error handling seems to miss a 'return'
statement.

Fix this by moving io_event_create() call around so we do not
need the Conn_Close/Init calls in the error case.
-rw-r--r--src/ngircd/conn.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c
index 26e47c1d..3350e208 100644
--- a/src/ngircd/conn.c
+++ b/src/ngircd/conn.c
@@ -1951,6 +1951,12 @@ New_Server( int Server , ng_ipaddr_t *dest)
 		return;
 	}
 
+	if (!io_event_create( new_sock, IO_WANTWRITE, cb_connserver)) {
+		Log(LOG_ALERT, "io_event_create(): could not add fd %d", strerror(errno));
+		close(new_sock);
+		return;
+	}
+
 	My_Connections = array_start(&My_ConnArray);
 
 	assert(My_Connections[new_sock].sock <= 0);
@@ -1961,7 +1967,7 @@ New_Server( int Server , ng_ipaddr_t *dest)
 	c = Client_NewLocal(new_sock, ip_str, CLIENT_UNKNOWNSERVER, false);
 	if (!c) {
 		Log( LOG_ALERT, "Can't establish connection: can't create client structure!" );
-		close( new_sock );
+		io_close(new_sock);
 		return;
 	}
 
@@ -1978,13 +1984,6 @@ New_Server( int Server , ng_ipaddr_t *dest)
 	strlcpy( My_Connections[new_sock].host, Conf_Server[Server].host,
 				sizeof(My_Connections[new_sock].host ));
 
-	/* Register new socket */
-	if (!io_event_create( new_sock, IO_WANTWRITE, cb_connserver)) {
-		Log( LOG_ALERT, "io_event_create(): could not add fd %d", strerror(errno));
-		Conn_Close( new_sock, "io_event_create() failed", NULL, false );
-		Init_Conn_Struct( new_sock );
-		Conf_Server[Server].conn_id = NONE;
-	}
 #ifdef SSL_SUPPORT
 	if (Conf_Server[Server].SSLConnect && !ConnSSL_PrepareConnect( &My_Connections[new_sock],
 								&Conf_Server[Server] ))
@@ -2025,9 +2024,10 @@ Init_Conn_Struct(CONN_ID Idx)
  * Initialize options of a new socket.
  *
  * For example, we try to set socket options SO_REUSEADDR and IPTOS_LOWDELAY.
- * Errors shouldn't be fatal and therefore are ignored.
+ * The socket is automatically closed if a fatal error is encountered.
  *
  * @param Sock	Socket handle.
+ * @returns false if socket was closed due to fatal error.
  */
 static bool
 Init_Socket( int Sock )