[Asterisk-cvs] asterisk/channels chan_sip.c,1.263,1.264

markster at lists.digium.com markster at lists.digium.com
Fri Dec 19 10:23:17 CST 2003


Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/tmp/cvs-serv21003/channels

Modified Files:
	chan_sip.c 
Log Message:
Fix reload race in SIP


Index: chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.263
retrieving revision 1.264
diff -u -d -r1.263 -r1.264
--- chan_sip.c	13 Dec 2003 22:54:37 -0000	1.263
+++ chan_sip.c	19 Dec 2003 16:14:51 -0000	1.264
@@ -1375,7 +1375,6 @@
 		ast_mutex_lock(&usecnt_lock);
 		usecnt++;
 		ast_mutex_unlock(&usecnt_lock);
-		ast_update_use_count();
 		strncpy(tmp->context, i->context, sizeof(tmp->context)-1);
 		strncpy(tmp->exten, i->exten, sizeof(tmp->exten)-1);
 		if (strlen(i->callerid))
@@ -4953,7 +4952,7 @@
 	return 0;
 }
 
-static int handle_request(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin)
+static int handle_request(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int *recount)
 {
 	/* Called with p->lock held, as well as p->owner->lock if appropriate, keeping things
 	   relatively static */
@@ -5128,6 +5127,7 @@
 				p->tag = rand();
 				/* First invitation */
 				c = sip_new(p, AST_STATE_DOWN, strlen(p->username) ? p->username : NULL);
+				*recount = 1;
 				/* Save Record-Route for any later requests we make on this dialogue */
 				build_route(p, req, 0);
 				if (c) {
@@ -5407,6 +5407,7 @@
 	struct sip_pvt *p;
 	int res;
 	int len;
+	int recount = 0;
 	len = sizeof(sin);
 	memset(&req, 0, sizeof(req));
 	res = recvfrom(sipsock, req.data, sizeof(req.data) - 1, 0, (struct sockaddr *)&sin, &len);
@@ -5439,12 +5440,15 @@
 			goto retrylock;
 		}
 		memcpy(&p->recv, &sin, sizeof(p->recv));
-		handle_request(p, &req, &sin);
+		handle_request(p, &req, &sin, &recount);
 		if (p->owner)
 			ast_mutex_unlock(&p->owner->lock);
 		ast_mutex_unlock(&p->lock);
 	}
 	ast_mutex_unlock(&netlock);
+	if (recount)
+		ast_update_use_count();
+
 	return 1;
 }
 
@@ -5778,6 +5782,7 @@
 	tmpc = sip_new(p, AST_STATE_DOWN, host);
 	if (!tmpc)
 		sip_destroy(p);
+	ast_update_use_count();
 	restart_monitor();
 	return tmpc;
 }




More information about the svn-commits mailing list