[sr-dev] git:master:0e8ef73c: pv: fix memory leak when getting $conid

Camille Oudot camille.oudot at orange.com
Mon Apr 13 17:24:06 CEST 2015


Module: kamailio
Branch: master
Commit: 0e8ef73c2095a7564735a1dab9ed32e3531fc59e
URL: https://github.com/kamailio/kamailio/commit/0e8ef73c2095a7564735a1dab9ed32e3531fc59e

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

pv: fix memory leak when getting $conid

---

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

---

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

---

diff --git a/modules/pv/pv_core.c b/modules/pv/pv_core.c
index dececb6..a4eab9a 100644
--- a/modules/pv/pv_core.c
+++ b/modules/pv/pv_core.c
@@ -1874,6 +1874,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;
@@ -1881,7 +1882,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 5553921..df778ba 100644
--- a/tcp_main.c
+++ b/tcp_main.c
@@ -1411,6 +1411,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