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

Luigi Rizzo rizzo at icir.org
Tue Jan 16 16:32:09 MST 2007


On Tue, Jan 16, 2007 at 09:56:40PM -0000, asterisk-commits at lists.digium.com wrote:
> 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

just a note, you seem to have left an ast_calloc() that should have
been alloca() in the first chunk...

	cheers
	luigi

> 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)
> 
> _______________________________________________
> --Bandwidth and Colocation provided by Easynews.com --
> 
> asterisk-commits mailing list
> To UNSUBSCRIBE or update options visit:
>    http://lists.digium.com/mailman/listinfo/asterisk-commits


More information about the asterisk-dev mailing list