Browse code

tcp: fix tcp_*_destroy() bug case

Mark unhashed connections in the "bug" code path to avoid
attempting to remove them twice.

Andrei Pelinescu-Onciul authored on 04/05/2011 22:35:31
Showing 1 changed files
... ...
@@ -1396,6 +1396,7 @@ static inline void _tcpconn_detach(struct tcp_connection *c)
1396 1396
 	for (r=0; r<c->aliases; r++)
1397 1397
 		tcpconn_listrm(tcpconn_aliases_hash[c->con_aliases[r].hash], 
1398 1398
 						&c->con_aliases[r], next, prev);
1399
+	c->aliases = 0;
1399 1400
 }
1400 1401
 
1401 1402
 
... ...
@@ -1433,6 +1434,7 @@ void tcpconn_rm(struct tcp_connection* c)
1433 1433
 	for (r=0; r<c->aliases; r++)
1434 1434
 		tcpconn_listrm(tcpconn_aliases_hash[c->con_aliases[r].hash], 
1435 1435
 						&c->con_aliases[r], next, prev);
1436
+	c->aliases = 0;
1436 1437
 	TCPCONN_UNLOCK;
1437 1438
 	lock_destroy(&c->write_lock);
1438 1439
 #ifdef USE_TLS
... ...
@@ -2985,6 +2987,7 @@ inline static void tcpconn_destroy(struct tcp_connection* tcpconn)
2985 2985
 				local_timer_del(&tcp_main_ltimer, &tcpconn->timer);
2986 2986
 			TCPCONN_LOCK;
2987 2987
 				_tcpconn_detach(tcpconn);
2988
+				tcpconn->flags &= ~(F_CONN_HASHED|F_CONN_MAIN_TIMER);
2988 2989
 			TCPCONN_UNLOCK;
2989 2990
 		}
2990 2991
 		if (likely(!(tcpconn->flags & F_CONN_FD_CLOSED))){
... ...
@@ -3022,6 +3025,7 @@ inline static int tcpconn_put_destroy(struct tcp_connection* tcpconn)
3022 3022
 				local_timer_del(&tcp_main_ltimer, &tcpconn->timer);
3023 3023
 			TCPCONN_LOCK;
3024 3024
 				_tcpconn_detach(tcpconn);
3025
+				tcpconn->flags &= ~(F_CONN_HASHED|F_CONN_MAIN_TIMER);
3025 3026
 			TCPCONN_UNLOCK;
3026 3027
 		}else{
3027 3028
 			LOG(L_CRIT, "BUG: tcpconn_put_destroy: %p flags = %0x\n",
... ...
@@ -4417,6 +4421,7 @@ static inline void tcpconn_destroy_all()
4417 4417
 					tls_close(c, fd);
4418 4418
 #endif
4419 4419
 				_tcpconn_rm(c);
4420
+				c->flags &= ~F_CONN_HASHED;
4420 4421
 				if (fd>0) {
4421 4422
 #ifdef TCP_FD_CACHE
4422 4423
 					if (likely(cfg_get(tcp, tcp_cfg, fd_cache)))