Browse code

pv: fix memory leak when getting $conid

Camille Oudot authored on 13/04/2015 15:04:41
Showing 2 changed files
... ...
@@ -1874,6 +1874,7 @@ int pv_get_tcpconn_id(struct sip_msg *msg, pv_param_t *param,
1874 1874
 		pv_value_t *res)
1875 1875
 {
1876 1876
 	struct tcp_connection *con;
1877
+	int conid;
1877 1878
 
1878 1879
 	if (msg == NULL)
1879 1880
 		return -1;
... ...
@@ -1881,7 +1882,10 @@ int pv_get_tcpconn_id(struct sip_msg *msg, pv_param_t *param,
1881 1881
 	if ((con = tcpconn_get(msg->rcv.proto_reserved1, 0, 0, 0, 0)) == NULL)
1882 1882
 		return pv_get_null(msg, param, res);
1883 1883
 
1884
-	return pv_get_sintval(msg, param, res, con->id);
1884
+	conid = con->id;
1885
+	tcpconn_put(con);
1886
+
1887
+	return pv_get_sintval(msg, param, res, conid);
1885 1888
 }
1886 1889
 
1887 1890
 
... ...
@@ -1411,6 +1411,8 @@ struct tcp_connection* _tcpconn_find(int id, struct ip_addr* ip, int port,
1411 1411
 /* _tcpconn_find with locks and timeout
1412 1412
  * local_addr contains the desired local ip:port. If null any local address 
1413 1413
  * will be used.  IN*ADDR_ANY or 0 port are wild cards.
1414
+ * If found, the connection's reference counter will be incremented, you might
1415
+ * want to decrement it after use.
1414 1416
  */
1415 1417
 struct tcp_connection* tcpconn_get(int id, struct ip_addr* ip, int port,
1416 1418
 									union sockaddr_union* local_addr,