[asterisk-commits] tilghman: branch 1.6.2 r268819 - in /branches/1.6.2: ./ channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 7 17:59:57 CDT 2010


Author: tilghman
Date: Mon Jun  7 17:59:52 2010
New Revision: 268819

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=268819
Log:
Merged revisions 268817 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
  r268817 | tilghman | 2010-06-07 17:47:13 -0500 (Mon, 07 Jun 2010) | 9 lines
  
  Mailbox list would previously grow at each reload, containing duplicates.
  
  Also, optimize the allocation of mailboxes to avoid additional memory structures.
  
  (closes issue #16320)
   Reported by: Marquis
   Patches: 
         20100525__issue16320.diff.txt uploaded by tilghman (license 14)
........

Modified:
    branches/1.6.2/   (props changed)
    branches/1.6.2/channels/chan_sip.c

Propchange: branches/1.6.2/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.

Modified: branches/1.6.2/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.2/channels/chan_sip.c?view=diff&rev=268819&r1=268818&r2=268819
==============================================================================
--- branches/1.6.2/channels/chan_sip.c (original)
+++ branches/1.6.2/channels/chan_sip.c Mon Jun  7 17:59:52 2010
@@ -1808,6 +1808,7 @@
 struct sip_mailbox {
 	char *mailbox;
 	char *context;
+	unsigned int delme:1;
 	/*! Associated MWI subscription */
 	struct ast_event_sub *event_sub;
 	AST_LIST_ENTRY(sip_mailbox) entry;
@@ -23788,15 +23789,30 @@
 
 	while ((mbox = context = strsep(&next, ","))) {
 		struct sip_mailbox *mailbox;
-
-		if (!(mailbox = ast_calloc(1, sizeof(*mailbox))))
+		int duplicate = 0;
+
+		strsep(&context, "@");
+
+		if (ast_strlen_zero(mbox)) {
 			continue;
-
-		strsep(&context, "@");
-		if (ast_strlen_zero(mbox)) {
-			ast_free(mailbox);
+		}
+
+		/* Check whether the mailbox is already in the list */
+		AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) {
+			if (!strcmp(mailbox->mailbox, mbox) && !strcmp(S_OR(mailbox->context, ""), S_OR(context, ""))) {
+				duplicate = 1;
+				mailbox->delme = 1;
+				break;
+			}
+		}
+		if (duplicate) {
 			continue;
 		}
+
+		if (!(mailbox = ast_calloc(1, sizeof(*mailbox)))) {
+			continue;
+		}
+
 		mailbox->mailbox = ast_strdup(mbox);
 		mailbox->context = ast_strdup(context);
 
@@ -23880,6 +23896,13 @@
 	peer->auth = NULL;
 	peer->default_outbound_transport = 0;
 	peer->transports = 0;
+
+	if (!devstate_only) {
+		struct sip_mailbox *mailbox;
+		AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) {
+			mailbox->delme = 1;
+		}
+	}
 
 	for (; v || ((v = alt) && !(alt=NULL)); v = v->next) {
 		if (!devstate_only) {
@@ -24230,6 +24253,17 @@
 		}
 	}
 
+	if (!devstate_only) {
+		struct sip_mailbox *mailbox;
+		AST_LIST_TRAVERSE_SAFE_BEGIN(&peer->mailboxes, mailbox, entry) {
+			if (mailbox->delme) {
+				AST_LIST_REMOVE_CURRENT(entry);
+				destroy_mailbox(mailbox);
+			}
+		}
+		AST_LIST_TRAVERSE_SAFE_END;
+	}
+
 	if (!peer->default_outbound_transport) {
 		/* Set default set of transports */
 		peer->transports = default_transports;




More information about the asterisk-commits mailing list