repo: ngircd action: commit revision: path_from: revision_from: 42b32f8a2adcbe0d7b011083cc0549ae89139449: path_to: revision_to:
commit 42b32f8a2adcbe0d7b011083cc0549ae89139449 Author: Florian WestphalDate: Sun Jun 5 15:00:32 2011 +0200 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. diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c
--- 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 )
-----END OF PAGE-----