[asterisk-commits] russell: branch group/issue_11972 r106891 - /team/group/issue_11972/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 7 16:32:48 CST 2008


Author: russell
Date: Fri Mar  7 16:32:48 2008
New Revision: 106891

URL: http://svn.digium.com/view/asterisk?view=rev&rev=106891
Log:
fix up some reference issues

Modified:
    team/group/issue_11972/channels/chan_sip.c

Modified: team/group/issue_11972/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/group/issue_11972/channels/chan_sip.c?view=diff&rev=106891&r1=106890&r2=106891
==============================================================================
--- team/group/issue_11972/channels/chan_sip.c (original)
+++ team/group/issue_11972/channels/chan_sip.c Fri Mar  7 16:32:48 2008
@@ -2131,14 +2131,6 @@
 
 static void *_sip_tcp_helper_thread(struct sip_pvt *pvt, struct ast_tcptls_server_instance *ser);
 
-static void *sip_tcp_helper_thread(void *data)
-{
-	struct sip_pvt *pvt = data;
-	struct ast_tcptls_server_instance *ser = ({ ao2_ref(pvt->socket.ser, +1); (ser); });
-
-	return _sip_tcp_helper_thread(pvt, ser);
-}
-
 static void *sip_tcp_worker_fn(void *data)
 {
 	struct ast_tcptls_server_instance *ser = data;
@@ -2152,7 +2144,7 @@
 	int res, cl;
 	struct sip_request req = { 0, } , reqcpy = { 0, };
 	struct sip_threadinfo *me;
-	char buf[1024];
+	char buf[1024] = "";
 
 	me = ast_calloc(1, sizeof(*me));
 
@@ -18119,13 +18111,18 @@
 
 	if ((ser = sip_tcp_locate(&ca.sin))) {
 		s->fd = ser->fd;
-		s->ser = ({ ao2_ref(ser, +1); (ser); });
+		if (s->ser) {
+			ao2_ref(s->ser, -1);
+			s->ser = NULL;
+		}
+		ao2_ref(ser, +1);
+		s->ser = ser;
 		return s->fd;
 	}
 
-	if (s->ser && s->ser->parent->tls_cfg) 
+	if (s->ser && s->ser->parent->tls_cfg) {
 		ca.tls_cfg = s->ser->parent->tls_cfg;
-	else {
+	} else {
 		if (s->type & SIP_TRANSPORT_TLS) {
 			ca.tls_cfg = ast_calloc(1, sizeof(*ca.tls_cfg));
 			if (!ca.tls_cfg)
@@ -18135,7 +18132,12 @@
 				ast_copy_string(ca.hostname, p->tohost, sizeof(ca.hostname));
 		}
 	}
-	s->ser = (!s->ser) ? ast_tcptls_client_start(&ca) : ({ ao2_ref(s->ser, +1); (s->ser); });
+	
+	if (s->ser) {
+		/* the pvt socket already has a server instance ... */
+	} else {
+		s->ser = ast_tcptls_client_start(&ca);
+	}
 
 	if (!s->ser) {
 		if (ca.tls_cfg)
@@ -18145,8 +18147,12 @@
 
 	s->fd = ca.accept_fd;
 
-	if (ast_pthread_create_background(&ca.master, NULL, sip_tcp_helper_thread, p)) {
+	/* Give the new thread a reference */
+	ao2_ref(s->ser, +1);
+
+	if (ast_pthread_create_background(&ca.master, NULL, sip_tcp_worker_fn, s->ser)) {
 		ast_debug(1, "Unable to launch '%s'.", ca.name);
+		ao2_ref(s->ser, -1);
 		close(ca.accept_fd);
 		s->fd = ca.accept_fd = -1;
 	}




More information about the asterisk-commits mailing list