Explorar o código

pv: fix memory leak when getting $conid

Camille Oudot %!s(int64=10) %!d(string=hai) anos
pai
achega
0e8ef73c20
Modificáronse 2 ficheiros con 7 adicións e 1 borrados
  1. 5 1
      modules/pv/pv_core.c
  2. 2 0
      tcp_main.c

+ 5 - 1
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);
 }
 
 

+ 2 - 0
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,