[sr-dev] git:4.2:a23331fb: pv: fix memory leak when getting $conid

Camille Oudot camille.oudot at orange.com
Mon Apr 13 17:26:58 CEST 2015


Module: kamailio
Branch: 4.2
Commit: a23331fbe5392cb6902dfd891b02162c65874f21
URL: https://github.com/kamailio/kamailio/commit/a23331fbe5392cb6902dfd891b02162c65874f21

Author: Camille Oudot <camille.oudot at orange.com>
Committer: Camille Oudot <camille.oudot at orange.com>
Date: 2015-04-13T17:26:45+02:00

pv: fix memory leak when getting $conid

cherry-picked from 0e8ef73c2095a7564735a1dab9ed32e3531fc59e

---

Modified: modules/pv/pv_core.c
Modified: tcp_main.c

---

Diff:  https://github.com/kamailio/kamailio/commit/a23331fbe5392cb6902dfd891b02162c65874f21.diff
Patch: https://github.com/kamailio/kamailio/commit/a23331fbe5392cb6902dfd891b02162c65874f21.patch

---

diff --git a/modules/pv/pv_core.c b/modules/pv/pv_core.c
index 724ceb8..56253b8 100644
--- a/modules/pv/pv_core.c
+++ b/modules/pv/pv_core.c
@@ -1894,6 +1894,7 @@ int pv_get_tcpconn_id(struct sip_msg *msg, pv_param_t *param,
 		pv_value_t *res)
 {
 	struct tcp_connection *con;
+	int conid;
 
 	if (msg == NULL)
 		return -1;
@@ -1901,7 +1902,10 @@ int pv_get_tcpconn_id(struct sip_msg *msg, pv_param_t *param,
 	if ((con = tcpconn_get(msg->rcv.proto_reserved1, 0, 0, 0, 0)) == NULL)
 		return pv_get_null(msg, param, res);
 
-	return pv_get_sintval(msg, param, res, con->id);
+	conid = con->id;
+	tcpconn_put(con);
+
+	return pv_get_sintval(msg, param, res, conid);
 }
 
 
diff --git a/tcp_main.c b/tcp_main.c
index 5af279f..5830c8e 100644
--- a/tcp_main.c
+++ b/tcp_main.c
@@ -1498,6 +1498,8 @@ struct tcp_connection* _tcpconn_find(int id, struct ip_addr* ip, int port,
 /* _tcpconn_find with locks and timeout
  * local_addr contains the desired local ip:port. If null any local address 
  * will be used.  IN*ADDR_ANY or 0 port are wild cards.
+ * If found, the connection's reference counter will be incremented, you might
+ * want to decrement it after use.
  */
 struct tcp_connection* tcpconn_get(int id, struct ip_addr* ip, int port,
 									union sockaddr_union* local_addr,




More information about the sr-dev mailing list