Browse code

core: tcp - test connection reference counter to avoid going negative

Daniel-Constantin Mierla authored on 03/07/2020 21:00:24
Showing 1 changed files
... ...
@@ -3263,7 +3263,8 @@ inline static int tcpconn_put_destroy(struct tcp_connection* tcpconn)
3263 3263
 	 * the refcnt. and at least a membar_write_atomic_op() mem. barrier or
3264 3264
 	 *  a mb_atomic_* op must * be used to make sure all the changed flags are
3265 3265
 	 *  written into memory prior to the new refcnt value */
3266
-	if (unlikely(mb_atomic_dec_and_test(&tcpconn->refcnt))){
3266
+	if (unlikely((mb_atomic_get(&tcpconn->refcnt)==0)
3267
+				|| mb_atomic_dec_and_test(&tcpconn->refcnt))){
3267 3268
 		_tcpconn_free(tcpconn);
3268 3269
 		return 1;
3269 3270
 	}