[svn-commits] russell: branch 1.2 r48361 - /branches/1.2/channels/chan_iax2.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Sat Dec 9 08:45:39 MST 2006


Author: russell
Date: Sat Dec  9 09:45:37 2006
New Revision: 48361

URL: http://svn.digium.com/view/asterisk?view=rev&rev=48361
Log:
Use locking when accessing the registrations list.  This list is not actually
used very often, so the likelihood of there being a problem is pretty small,
but still possible.  For example, if the CLI command to list the registrations
was called at the same time that a reload was occurring and the registrations
list was getting destroyed and rebuilt, a crash could occur.

Modified:
    branches/1.2/channels/chan_iax2.c

Modified: branches/1.2/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/channels/chan_iax2.c?view=diff&rev=48361&r1=48360&r2=48361
==============================================================================
--- branches/1.2/channels/chan_iax2.c (original)
+++ branches/1.2/channels/chan_iax2.c Sat Dec  9 09:45:37 2006
@@ -410,6 +410,7 @@
 };
 
 static struct iax2_registry *registrations;
+AST_MUTEX_DEFINE_STATIC(reg_lock);
 
 /* Don't retry more frequently than every 10 ms, or less frequently than every 5 seconds */
 #define MIN_RETRY_TIME		100
@@ -4399,8 +4400,8 @@
 	char iabuf[INET_ADDRSTRLEN];
 	if (argc != 3)
 		return RESULT_SHOWUSAGE;
-	ast_mutex_lock(&peerl.lock);
 	ast_cli(fd, FORMAT2, "Host", "Username", "Perceived", "Refresh", "State");
+	ast_mutex_lock(&reg_lock);
 	for (reg = registrations;reg;reg = reg->next) {
 		snprintf(host, sizeof(host), "%s:%d", ast_inet_ntoa(iabuf, sizeof(iabuf), reg->addr.sin_addr), ntohs(reg->addr.sin_port));
 		if (reg->us.sin_addr.s_addr) 
@@ -4410,7 +4411,7 @@
 		ast_cli(fd, FORMAT, host, 
 					reg->username, perceived, reg->refresh, regstate2str(reg->regstate));
 	}
-	ast_mutex_unlock(&peerl.lock);
+	ast_mutex_unlock(&reg_lock);
 	return RESULT_SUCCESS;
 #undef FORMAT
 #undef FORMAT2
@@ -5624,9 +5625,11 @@
 		reg->addr.sin_family = AF_INET;
 		memcpy(&reg->addr.sin_addr, hp->h_addr, sizeof(&reg->addr.sin_addr));
 		reg->addr.sin_port = porta ? htons(atoi(porta)) : htons(IAX_DEFAULT_PORTNO);
+		ast_mutex_lock(&reg_lock);
 		reg->next = registrations;
 		reg->callno = 0;
 		registrations = reg;
+		ast_mutex_unlock(&reg_lock);
 	} else {
 		ast_log(LOG_ERROR, "Out of memory\n");
 		return -1;
@@ -8582,6 +8585,7 @@
 		user = user->next;
 	}
 	ast_mutex_unlock(&userl.lock);
+	ast_mutex_lock(&reg_lock);
 	for (reg = registrations;reg;) {
 		regl = reg;
 		reg = reg->next;
@@ -8600,6 +8604,7 @@
 		free(regl);
 	}
 	registrations = NULL;
+	ast_mutex_unlock(&reg_lock);
 	ast_mutex_lock(&peerl.lock);
 	for (peer=peerl.peers;peer;) {
 		/* Assume all will be deleted, and we'll find out for sure later */
@@ -8976,8 +8981,10 @@
 	set_config(config,1);
 	prune_peers();
 	prune_users();
+	ast_mutex_lock(&reg_lock);
 	for (reg = registrations; reg; reg = reg->next)
 		iax2_do_register(reg);
+	ast_mutex_unlock(&reg_lock);
 	/* Qualify hosts, too */
 	ast_mutex_lock(&peerl.lock);
 	for (peer = peerl.peers; peer; peer = peer->next)
@@ -9742,8 +9749,10 @@
 		ast_netsock_release(netsock);
 	}
 
+	ast_mutex_lock(&reg_lock);
 	for (reg = registrations; reg; reg = reg->next)
 		iax2_do_register(reg);
+	ast_mutex_unlock(&reg_lock);
 	ast_mutex_lock(&peerl.lock);
 	for (peer = peerl.peers; peer; peer = peer->next) {
 		if (peer->sockfd < 0)



More information about the svn-commits mailing list