Module: kamailio
Branch: master
Commit: 6a637cf84906ec5315c77e5458180f7d9d69a481
URL:
https://github.com/kamailio/kamailio/commit/6a637cf84906ec5315c77e5458180f7…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2020-07-03T23:00:24+02:00
core: tcp - test connection reference counter to avoid going negative
---
Modified: src/core/tcp_main.c
---
Diff:
https://github.com/kamailio/kamailio/commit/6a637cf84906ec5315c77e5458180f7…
Patch:
https://github.com/kamailio/kamailio/commit/6a637cf84906ec5315c77e5458180f7…
---
diff --git a/src/core/tcp_main.c b/src/core/tcp_main.c
index fd5a644ee5..f19f75a588 100644
--- a/src/core/tcp_main.c
+++ b/src/core/tcp_main.c
@@ -3263,7 +3263,8 @@ inline static int tcpconn_put_destroy(struct tcp_connection*
tcpconn)
* the refcnt. and at least a membar_write_atomic_op() mem. barrier or
* a mb_atomic_* op must * be used to make sure all the changed flags are
* written into memory prior to the new refcnt value */
- if (unlikely(mb_atomic_dec_and_test(&tcpconn->refcnt))){
+ if (unlikely((mb_atomic_get(&tcpconn->refcnt)==0)
+ || mb_atomic_dec_and_test(&tcpconn->refcnt))){
_tcpconn_free(tcpconn);
return 1;
}