浏览代码

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 14 年之前
父节点
当前提交
a8859f52b9
共有 1 个文件被更改,包括 4 次插入4 次删除
  1. 4 4
      tcp_main.c

+ 4 - 4
tcp_main.c

@@ -4036,8 +4036,8 @@ static inline int handle_new_connect(struct socket_info* si)
 			su2a(&su, sizeof(su)), tcpconn, tcpconn->s, tcpconn->flags);
 		if(unlikely(send2child(tcpconn)<0)){
 			tcpconn->flags&=~F_CONN_READER;
-			tcpconn_put(tcpconn);
-			tcpconn_try_unhash(tcpconn);
+			if (tcpconn_try_unhash(tcpconn))
+				tcpconn_put(tcpconn);
 			tcpconn_put_destroy(tcpconn);
 		}
 #endif
@@ -4226,8 +4226,8 @@ send_to_child:
 				tcpconn->flags&=~F_CONN_WRITE_W;
 			}
 #endif /* TCP_ASYNC */
-			tcpconn_put(tcpconn);
-			tcpconn_try_unhash(tcpconn); 
+			if (tcpconn_try_unhash(tcpconn))
+				tcpconn_put(tcpconn);
 			tcpconn_put_destroy(tcpconn); /* because of the tcpconn_ref() */
 		}
 	}