[asterisk-commits] anthonyl: branch anthonyl/voicemail-odbc r48511 - /team/anthonyl/voicemail-od...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Dec 15 17:08:23 MST 2006


Author: anthonyl
Date: Fri Dec 15 18:08:22 2006
New Revision: 48511

URL: http://svn.digium.com/view/asterisk?view=rev&rev=48511
Log:
update: it's faster to place dest onto the stack rather then needing to allocate and free it all of the time

Modified:
    team/anthonyl/voicemail-odbc/apps/app_voicemail.c

Modified: team/anthonyl/voicemail-odbc/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/voicemail-odbc/apps/app_voicemail.c?view=diff&rev=48511&r1=48510&r2=48511
==============================================================================
--- team/anthonyl/voicemail-odbc/apps/app_voicemail.c (original)
+++ team/anthonyl/voicemail-odbc/apps/app_voicemail.c Fri Dec 15 18:08:22 2006
@@ -1943,21 +1943,14 @@
 {
 	int res;
 	char fn[256];
-	char *dest;
+	char dest[1024];
 	
 	snprintf(fn, sizeof(fn), "%s%s/%s/greet", VM_SPOOL_DIR, context, ext);
-
-	if (!(dest = malloc(1024))) {
-	      ast_log(LOG_WARNING, "Failed memory allocation\n");
-	      return -1;
-	}
-
-	if (!(res=create_dirpath(dest,1024,context,ext,"greet"))) {
+	
+	if (!(res=create_dirpath(&dest,1024,context,ext,"greet"))) {
 	      ast_log(LOG_WARNING, "Failed to make directory(%s)\n", fn);
 	      return -1;
 	}
-	free(dest);
-
 	RETRIEVE(fn, -1);
 	if (ast_fileexists(fn, NULL, NULL) > 0) {
 		res = ast_streamfile(chan, fn, chan->language);
@@ -2405,6 +2398,7 @@
 	int ouseexten = 0;
 	char date[256];
 	char dir[256], tmpdir[260];
+	char dest[1024];
 	char fn[256];
 	char prefile[256]="";
 	char tempfile[256]="";
@@ -2416,7 +2410,6 @@
 	struct ast_vm_user *vmu;
 	struct ast_vm_user svm;
 	char *category = NULL;
-	char *dest = NULL;
 
 	ast_copy_string(tmp, ext, sizeof(tmp));
 	ext = tmp;
@@ -2443,31 +2436,24 @@
 		pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED");
 		return res;
 	}
-
-	if (!(dest=malloc(1024))) {
-	       ast_log(LOG_WARNING, "Failed to allocate memory\n");
-	      return -1;
-	}
-	
 	/* Setup pre-file if appropriate */
 	if (strcmp(vmu->context, "default"))
 		snprintf(ext_context, sizeof(ext_context), "%s@%s", ext, vmu->context);
 	else
 		ast_copy_string(ext_context, vmu->context, sizeof(ext_context));
 	if (ast_test_flag(options, OPT_BUSY_GREETING)) {
-	        res = create_dirpath(dest, 1024, vmu->context, ext, "busy");
+	        res = create_dirpath(&dest, 1024, vmu->context, ext, "busy");
 		snprintf(prefile, sizeof(prefile), "%s%s/%s/busy", VM_SPOOL_DIR, vmu->context, ext);
 	}
 	else if (ast_test_flag(options, OPT_UNAVAIL_GREETING)) {
-	        res = create_dirpath(dest, 1024, vmu->context, ext, "unavail");
+	        res = create_dirpath(&dest, 1024, vmu->context, ext, "unavail");
 		snprintf(prefile, sizeof(prefile), "%s%s/%s/unavail", VM_SPOOL_DIR, vmu->context, ext);
 	}
 	snprintf(tempfile, sizeof(tempfile), "%s%s/%s/temp", VM_SPOOL_DIR, vmu->context, ext);
-	if (!(res=create_dirpath(dest, 1024, vmu->context, ext, "temp"))) {
+	if (!(res=create_dirpath(&dest, 1024, vmu->context, ext, "temp"))) {
 	      ast_log(LOG_WARNING, "Failed to make directory (%s)\n", tempfile);
 	      return -1;
 	}
-	free(dest);
 	RETRIEVE(tempfile, -1);
 	if (ast_fileexists(tempfile, NULL, NULL) > 0)
 		ast_copy_string(prefile, tempfile, sizeof(prefile));
@@ -3602,11 +3588,6 @@
 	} else {
 		/* Forward VoiceMail */
 		long duration = 0;
-		if (!(dest=malloc(1024))) {
-		      ast_log(LOG_WARNING, "Memory allocation failed.\n");
-		      return -1;
-		}
-		
  		RETRIEVE(dir, curmsg);
 		cmd = vm_forwardoptions(chan, sender, dir, curmsg, vmfmts, context, record_gain, &duration);
 		if (!cmd) {
@@ -4828,8 +4809,8 @@
 	int duration = 0;
 	char prefile[256]="";
 	unsigned char buf[256];
+	char dest[1024];
 	int bytes=0;
-	char *dest;
 
 	if (adsi_available(chan))
 	{
@@ -4841,11 +4822,7 @@
 		adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
 	}
 	snprintf(prefile,sizeof(prefile), "%s%s/%s/temp", VM_SPOOL_DIR, vmu->context, vms->username);
-	if (!(dest=malloc(1024))) {
-	      ast_log(LOG_WARNING, "Failed memory allocation.\n");
-	      return -1;
-	}
-        if (!(res=create_dirpath(dest, 1024, vmu->context, vms->username, "temp"))) {
+        if (!(res=create_dirpath(&dest, 1024, vmu->context, vms->username, "temp"))) {
 	      ast_log(LOG_WARNING, "Failed to create directory (%s).\n", prefile);
 	      return -1;
 	}



More information about the asterisk-commits mailing list