[asterisk-commits] tilghman: branch 1.6.1 r177539 - in /branches/1.6.1: ./ apps/app_voicemail.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Feb 19 16:35:48 CST 2009


Author: tilghman
Date: Thu Feb 19 16:35:48 2009
New Revision: 177539

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=177539
Log:
Merged revisions 177537 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
  r177537 | tilghman | 2009-02-19 16:33:00 -0600 (Thu, 19 Feb 2009) | 14 lines
  
  Merged revisions 177536 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.4
  
  ........
    r177536 | tilghman | 2009-02-19 16:26:01 -0600 (Thu, 19 Feb 2009) | 7 lines
    
    Fix up potential crashes, by reducing the sharing between interactive and non-interactive threads.
    (closes issue #14253)
     Reported by: Skavin
     Patches: 
           20090219__bug14253.diff.txt uploaded by Corydon76 (license 14)
     Tested by: Skavin
  ........
................

Modified:
    branches/1.6.1/   (props changed)
    branches/1.6.1/apps/app_voicemail.c

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

Modified: branches/1.6.1/apps/app_voicemail.c
URL: http://svn.digium.com/svn-view/asterisk/branches/1.6.1/apps/app_voicemail.c?view=diff&rev=177539&r1=177538&r2=177539
==============================================================================
--- branches/1.6.1/apps/app_voicemail.c (original)
+++ branches/1.6.1/apps/app_voicemail.c Thu Feb 19 16:35:48 2009
@@ -116,6 +116,10 @@
 #endif
 
 #ifdef IMAP_STORAGE
+#include "asterisk/threadstorage.h"
+
+AST_MUTEX_DEFINE_STATIC(imaptemp_lock);
+static char imaptemp[1024];
 static char imapserver[48];
 static char imapport[8];
 static char imapflags[128];
@@ -131,6 +135,8 @@
 
 struct vm_state;
 struct ast_vm_user;
+
+AST_THREADSTORAGE(ts_vmstate, ts_vmstate_init);
 
 /* Forward declarations for IMAP */
 static int init_mailstream(struct vm_state *vms, int box);
@@ -2389,7 +2395,7 @@
 		pquota = pquota->next;
 	}
 	
-	if (!(user = get_user_by_mailbox(mailbox, buf, sizeof(buf))) || !(vms = get_vm_state_by_imapuser(user, 2))) {
+	if (!(user = get_user_by_mailbox(mailbox, buf, sizeof(buf))) || (!(vms = get_vm_state_by_imapuser(user, 2)) && !(vms = get_vm_state_by_imapuser(user, 0)))) {
 		ast_log(AST_LOG_ERROR, "No state found.\n");
 		return;
 	}
@@ -2452,6 +2458,9 @@
 {
 	struct vm_state *vms_p;
 
+	if ((vms_p = pthread_getspecific(ts_vmstate.key)) && !strcmp(vms_p->imapuser, vmu->imapuser) && !strcmp(vms_p->username, vmu->mailbox)) {
+		return vms_p;
+	}
 	if (option_debug > 4)
 		ast_log(AST_LOG_DEBUG,"Adding new vmstate for %s\n",vmu->imapuser);
 	if (!(vms_p = ast_calloc(1, sizeof(*vms_p))))
@@ -2474,6 +2483,12 @@
 {
 	struct vmstate *vlist = NULL;
 
+	if (interactive) {
+		struct vm_state *vms;
+		vms = pthread_getspecific(ts_vmstate.key);
+		return vms;
+	}
+
 	AST_LIST_LOCK(&vmstates);
 	AST_LIST_TRAVERSE(&vmstates, vlist, list) {
 		if (!vlist->vms) {
@@ -2502,6 +2517,12 @@
 
 	struct vmstate *vlist = NULL;
 	const char *local_context = S_OR(context, "default");
+
+	if (interactive) {
+		struct vm_state *vms;
+		vms = pthread_getspecific(ts_vmstate.key);
+		return vms;
+	}
 
 	AST_LIST_LOCK(&vmstates);
 	AST_LIST_TRAVERSE(&vmstates, vlist, list) {
@@ -2549,9 +2570,13 @@
 			/* get a pointer to the persistent store */
 			vms->persist_vms = altvms;
 			/* Reuse the mailstream? */
+#ifdef REALLY_FAST_EVEN_IF_IT_MEANS_RESOURCE_LEAKS
 			vms->mailstream = altvms->mailstream;
-			/* vms->mailstream = NIL; */
-		}
+#else
+			vms->mailstream = NIL;
+#endif
+		}
+		return;
 	}
 
 	if (!(v = ast_calloc(1, sizeof(*v))))
@@ -2578,6 +2603,10 @@
 		altvms->newmessages = vms->newmessages;
 		altvms->oldmessages = vms->oldmessages;
 		altvms->updated = 1;
+		vms->mailstream = mail_close(vms->mailstream);
+
+		/* Interactive states are not stored within the persistent list */
+		return;
 	}
 	
 	ast_debug(3, "Removing vm_state for user:%s, mailbox %s\n", vms->imapuser, vms->username);
@@ -8790,6 +8819,9 @@
 	adsi_begin(chan, &useadsi);
 
 #ifdef IMAP_STORAGE
+	pthread_once(&ts_vmstate.once, ts_vmstate.key_init);
+	pthread_setspecific(ts_vmstate.key, &vms);
+
 	vms.interactive = 1;
 	vms.updated = 1;
 	if (vmu)
@@ -9360,6 +9392,9 @@
 	if (vms.heard)
 		ast_free(vms.heard);
 
+#ifdef IMAP_STORAGE
+	pthread_setspecific(ts_vmstate.key, NULL);
+#endif
 	return res;
 }
 




More information about the asterisk-commits mailing list