[sr-dev] git:master:889a82f8: tcpops: release tcp connection id in w_tcp_conid_state()

Daniel-Constantin Mierla miconda at gmail.com
Thu Oct 1 22:02:41 CEST 2015


Module: kamailio
Branch: master
Commit: 889a82f8b61620c224cc9eca4bd5b41369aa6fae
URL: https://github.com/kamailio/kamailio/commit/889a82f8b61620c224cc9eca4bd5b41369aa6fae

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2015-10-01T21:59:12+02:00

tcpops: release tcp connection id in w_tcp_conid_state()

- tcpconn_get() increases reference number, tcpconn_put() is required,
  otherwise the associated structure won't be destroyed after close
- debug message for unexpected connection state reworked

---

Modified: modules/tcpops/tcpops_mod.c

---

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

---

diff --git a/modules/tcpops/tcpops_mod.c b/modules/tcpops/tcpops_mod.c
index c1c75e0..8241760 100644
--- a/modules/tcpops/tcpops_mod.c
+++ b/modules/tcpops/tcpops_mod.c
@@ -231,32 +231,43 @@ static int w_tcp_conid_state(sip_msg_t* msg, char* conid, char *p2)
 
 	if (unlikely((s_con = tcpconn_get(i_conid, 0, 0, 0, 0)) == NULL)) {
 		LM_DBG("Connection id %d does not exist.\n", i_conid);
-		return -1;
+		ret = -1;
+		goto done;
 	} 
 	/* Connection structure exists, now check what Kamailio thinks of it */
 	if (s_con->state == S_CONN_OK) {
 		/* All is fine, return happily */
-		return 1;
+		ret = 1;
+		goto done;
 	}
 	if (s_con->state == S_CONN_EOF) {	/* Socket closed or about to close under our feet */
-		return -2;
+		ret = -2;
+		goto done;
 	}
 	if (s_con->state == S_CONN_ERROR) {	/* Error on read/write - will close soon */
-		return -3;
+		ret = -3;
+		goto done;
 	}
 	if (s_con->state == S_CONN_BAD) {	/* Unknown state */
-		return -4;
+		ret = -4;
+		goto done;
 	}
 	if (s_con->state == S_CONN_ACCEPT) {	/* Incoming connection to be set up */
-		return 2;
+		ret = 2;
+		goto done;
 	}
 	if (s_con->state == S_CONN_CONNECT) {	/* Outbound connection moving to S_CONN_OK */
-		return 3;
+		ret = 3;
+		goto done;
 	}
 	/* Wonder what state we're in here */
-	LM_DBG("Connection id %d is in state %d - go figure. I will treat is a good. If not, file a bug report please.\n", i_conid, s_con->flags);
-	
-	return 1;	/* Good connection */
+	LM_DBG("Connection id %d is in unexpected state %d - assuming ok.\n", i_conid, s_con->flags);
+
+	/* Good connection */
+	ret = 1;
+done:
+	if(s_con) tcpconn_put(s_con);
+	return ret;
 }
 
 static int w_tcpops_set_connection_lifetime2(sip_msg_t* msg, char* conid, char* time)




More information about the sr-dev mailing list