[asterisk-commits] anthonyl: branch anthonyl/voicemail-fixups r51164 - /team/anthonyl/voicemail-...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Jan 16 14:56:40 MST 2007


Author: anthonyl
Date: Tue Jan 16 15:56:39 2007
New Revision: 51164

URL: http://svn.digium.com/view/asterisk?view=rev&rev=51164
Log:
getting rid of dynamic memory allocations

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

Modified: team/anthonyl/voicemail-fixups/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/voicemail-fixups/apps/app_voicemail.c?view=diff&rev=51164&r1=51163&r2=51164
==============================================================================
--- team/anthonyl/voicemail-fixups/apps/app_voicemail.c (original)
+++ team/anthonyl/voicemail-fixups/apps/app_voicemail.c Tue Jan 16 15:56:39 2007
@@ -782,13 +782,8 @@
 					break;
 				}
 				len = (strlen(value) + strlen(newpassword));
-				
-				if (!(new = ast_calloc(1,len))) {
-					ast_log(LOG_WARNING, "Memory Allocation Failed.\n");
-					break;
-				}
+				new = ast_calloc(len+1);
 				sprintf(new,"%s%s", newpassword, value);
-	
 				if (!(cat = ast_category_get(cfg, category))) {
 					ast_log(LOG_WARNING, "Failed to get category structure.\n");
 					break;
@@ -800,8 +795,6 @@
 		reset_user_pw(vmu->context, vmu->mailbox, newpassword);
 		ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
 		config_text_file_save(VOICEMAIL_CONFIG, cfg, "AppVoicemail");
-		if (new)
-			free(new);
 	}
 	category = NULL;
 	var = NULL;
@@ -819,15 +812,12 @@
 						ast_log(LOG_DEBUG, "looks like we need to make vmpassword!\n");
 					var = ast_variable_new("vmpassword", newpassword);
 				} 
-				if (!(new = ast_calloc(1,strlen(newpassword)))) {
-					if (option_debug > 3)
-						ast_log(LOG_DEBUG, "Memory Allocation Failed.\n");
-					break;
-				} 
+				new = alloca(strlen(newpassword)+1);
 				sprintf(new, "%s", newpassword);
 				if (!(cat = ast_category_get(cfg, category))) {
 					if (option_debug > 3)
 						ast_log(LOG_DEBUG, "failed to get category!\n");
+					break;
 				}
 				if (!var)		
 					ast_variable_update(cat, "vmpassword", new, NULL);
@@ -839,10 +829,7 @@
 		reset_user_pw(vmu->context, vmu->mailbox, newpassword);	
 		ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
 		config_text_file_save("users.conf", cfg, "AppVoicemail");
-		if (new) 
-			free(new);
-	}
-
+	}
 }
 
 static void vm_change_password_shell(struct ast_vm_user *vmu, char *newpassword)



More information about the asterisk-commits mailing list