Browse code

tcp: fix send2child() error case

If send2child() fails don't decrement the refcnt if the connection
was already removed from the hash due to some other previous
error (very unlikely, but possible).

Andrei Pelinescu-Onciul authored on 04/05/2011 22:43:48
Showing 1 changed files
... ...
@@ -4036,8 +4036,8 @@ static inline int handle_new_connect(struct socket_info* si)
4036 4036
 			su2a(&su, sizeof(su)), tcpconn, tcpconn->s, tcpconn->flags);
4037 4037
 		if(unlikely(send2child(tcpconn)<0)){
4038 4038
 			tcpconn->flags&=~F_CONN_READER;
4039
-			tcpconn_put(tcpconn);
4040
-			tcpconn_try_unhash(tcpconn);
4039
+			if (tcpconn_try_unhash(tcpconn))
4040
+				tcpconn_put(tcpconn);
4041 4041
 			tcpconn_put_destroy(tcpconn);
4042 4042
 		}
4043 4043
 #endif
... ...
@@ -4226,8 +4226,8 @@ send_to_child:
4226 4226
 				tcpconn->flags&=~F_CONN_WRITE_W;
4227 4227
 			}
4228 4228
 #endif /* TCP_ASYNC */
4229
-			tcpconn_put(tcpconn);
4230
-			tcpconn_try_unhash(tcpconn); 
4229
+			if (tcpconn_try_unhash(tcpconn))
4230
+				tcpconn_put(tcpconn);
4231 4231
 			tcpconn_put_destroy(tcpconn); /* because of the tcpconn_ref() */
4232 4232
 		}
4233 4233
 	}