Przeglądaj źródła

- tcp_send fix: return <0 on send error.
This is a modified version of Klaus Darilion patch/openser port
(extra tcpconn_put on release error)

Andrei Pelinescu-Onciul 19 lat temu
rodzic
commit
bf458eea46
1 zmienionych plików z 7 dodań i 4 usunięć
  1. 7 4
      tcp_main.c

+ 7 - 4
tcp_main.c

@@ -729,7 +729,9 @@ void tcpconn_put(struct tcp_connection* c)
 
 
 
-/* finds a tcpconn & sends on it */
+/* finds a tcpconn & sends on it
+ * returns: number of bytes written (>=0) on success
+ *          <0 on error */
 int tcp_send(int type, char* buf, unsigned len, union sockaddr_union* to,
 				int id)
 {
@@ -848,13 +850,14 @@ send_it:
 		/* tell "main" it should drop this (optional it will t/o anyway?)*/
 		response[0]=(long)c;
 		response[1]=CONN_ERROR;
-		n=send_all(unix_tcp_sock, response, sizeof(response));
-		/* CONN_ERROR will auto-dec refcnt => we must not call tcpconn_put !!*/
-		if (n<=0){
+		if (send_all(unix_tcp_sock, response, sizeof(response))<=0){
 			LOG(L_ERR, "BUG: tcp_send: error return failed (write):%s (%d)\n",
 					strerror(errno), errno);
+			tcpconn_put(c); /* deref. it manually */
 			n=-1;
 		}
+		/* CONN_ERROR will auto-dec refcnt => we must not call tcpconn_put 
+		 * if it succeeds */
 		close(fd);
 		return n; /* error return, no tcpconn_put */
 	}