[svn-commits] mjordan: branch 11 r372289 - in /branches/11: ./ apps/app_voicemail.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Sep 5 08:47:37 CDT 2012


Author: mjordan
Date: Wed Sep  5 08:47:31 2012
New Revision: 372289

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=372289
Log:
Fix memory leaks in app_voicemail when using IMAP storage or realtime config

This patch fixes two memory leaks:

1. When find_user is called with NULL as its first parameter, the voicemail
   user returned is allocated on the heap.  The inboxcount2 function uses
   find_user in such a fashion when counting new messages, and fails to free
   the resulting voicemail user object.

2. When populate_defaults is called on a voicemail user, it wipes whatever
   flags have been set on the object by copying over the global flags object.
   If the VM_ALLOCED flag was ste on the voicemail user prior to doing so,
   that flag is removed.  This leaks the voicemail user when free_user is later
   called.

(closes issue ASTERISK-19155)
Reported by: Filip Jenicek
patches:
  asterisk.patch2 uploaded by Filip Jenicek (license 6277)

Patch slightly modified for this commit.

Review: https://reviewboard.asterisk.org/r/2096
........

Merged revisions 372268 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 372288 from http://svn.asterisk.org/svn/asterisk/branches/10

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

Propchange: branches/11/
------------------------------------------------------------------------------
Binary property 'branch-10-merged' - no diff available.

Modified: branches/11/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/apps/app_voicemail.c?view=diff&rev=372289&r1=372288&r2=372289
==============================================================================
--- branches/11/apps/app_voicemail.c (original)
+++ branches/11/apps/app_voicemail.c Wed Sep  5 08:47:31 2012
@@ -1577,17 +1577,21 @@
 	struct ast_vm_user *retval;
 
 	if ((retval = (ivm ? ivm : ast_calloc(1, sizeof(*retval))))) {
-		if (!ivm)
-			ast_set_flag(retval, VM_ALLOCED);	
-		else
+		if (ivm) {
 			memset(retval, 0, sizeof(*retval));
-		if (mailbox) 
+		}
+		populate_defaults(retval);
+		if (!ivm) {
+			ast_set_flag(retval, VM_ALLOCED);
+		}
+		if (mailbox) {
 			ast_copy_string(retval->mailbox, mailbox, sizeof(retval->mailbox));
-		populate_defaults(retval);
-		if (!context && ast_test_flag((&globalflags), VM_SEARCH))
+		}
+		if (!context && ast_test_flag((&globalflags), VM_SEARCH)) {
 			var = ast_load_realtime("voicemail", "mailbox", mailbox, SENTINEL);
-		else
+		} else {
 			var = ast_load_realtime("voicemail", "mailbox", mailbox, "context", context, SENTINEL);
+		}
 		if (var) {
 			apply_options_full(retval, var);
 			ast_variables_destroy(var);
@@ -2660,8 +2664,10 @@
 			return -1;
 		}
 		if ((*newmsgs = __messagecount(context, mailboxnc, vmu->imapfolder)) < 0) {
+			free_user(vmu);
 			return -1;
 		}
+		free_user(vmu);
 	}
 	if (oldmsgs) {
 		if ((*oldmsgs = __messagecount(context, mailboxnc, "Old")) < 0) {
@@ -2979,8 +2985,9 @@
 	vmu = ast_calloc(1, sizeof *vmu);
 	if (!vmu)
 		return NULL;
+
+	populate_defaults(vmu);
 	ast_set_flag(vmu, VM_ALLOCED);
-	populate_defaults(vmu);
 
 	var = ast_load_realtime("voicemail", "imapuser", imapuser, NULL);
 	if (var) {
@@ -11742,8 +11749,8 @@
 	if (!(vmu = ast_calloc(1, sizeof(*vmu)))) {
 		return AST_TEST_NOT_RUN;
 	}
+	populate_defaults(vmu);
 	ast_set_flag(vmu, VM_ALLOCED);
-	populate_defaults(vmu);
 
 	apply_options(vmu, options_string);
 
@@ -11871,7 +11878,7 @@
 		res = 1;
 	}
 	if (strcasecmp(vmu->imapfolder, "INBOX")) {
-		ast_test_status_update(test, "Parse failure for imappasswd option\n");
+		ast_test_status_update(test, "Parse failure for imapfolder option\n");
 		res = 1;
 	}
 	if (strcasecmp(vmu->imapvmshareid, "6000")) {




More information about the svn-commits mailing list