[Asterisk-cvs] asterisk/apps app_adsiprog.c, 1.16, 1.17 app_alarmreceiver.c, 1.16, 1.17 app_authenticate.c, 1.16, 1.17 app_cdr.c, 1.8, 1.9 app_chanisavail.c, 1.23, 1.24 app_chanspy.c, 1.26, 1.27 app_controlplayback.c, 1.14, 1.15 app_curl.c, 1.12, 1.13 app_cut.c, 1.15, 1.16 app_db.c, 1.14, 1.15 app_dial.c, 1.171, 1.172 app_dictate.c, 1.6, 1.7 app_directed_pickup.c, 1.4, 1.5 app_directory.c, 1.46, 1.47 app_disa.c, 1.35, 1.36 app_dumpchan.c, 1.11, 1.12 app_enumlookup.c, 1.22, 1.23 app_eval.c, 1.8, 1.9 app_externalivr.c, 1.10, 1.11 app_festival.c, 1.34, 1.35 app_groupcount.c, 1.22, 1.23 app_hasnewvoicemail.c, 1.18, 1.19 app_ices.c, 1.9, 1.10 app_image.c, 1.9, 1.10 app_intercom.c, 1.24, 1.25 app_ivrdemo.c, 1.9, 1.10 app_macro.c, 1.29, 1.30 app_math.c, 1.14, 1.15 app_md5.c, 1.9, 1.10 app_meetme.c, 1.113, 1.114 app_milliwatt.c, 1.13, 1.14 app_mp3.c, 1.28, 1.29 app_muxmon.c, 1.3, 1.4 app_nbscat.c, 1.13, 1.14 app_osplookup.c, 1.11, 1.12 app_page.c, 1.6, 1.7 app_parkandannounce.c, 1.17, 1.18 app_playback.c, 1.21, 1.22 app_queue.c, 1.171, 1.172 app_random.c, 1.9, 1.10 app_read.c, 1.23, 1.24 app_readfile.c, 1.9, 1.10 app_realtime.c, 1.13, 1.14 app_record.c, 1.38, 1.39 app_senddtmf.c, 1.12, 1.13 app_sendtext.c, 1.10, 1.11 app_setcallerid.c, 1.11, 1.12 app_setcdruserfield.c, 1.10, 1.11 app_setcidname.c, 1.12, 1.13 app_setcidnum.c, 1.13, 1.14 app_setrdnis.c, 1.8, 1.9 app_settransfercapability.c, 1.8, 1.9 app_skel.c, 1.14, 1.15 app_sms.c, 1.28, 1.29 app_softhangup.c, 1.10, 1.11 app_sql_postgres.c, 1.14, 1.15 app_striplsd.c, 1.8, 1.9 app_substring.c, 1.13, 1.14 app_system.c, 1.19, 1.20 app_talkdetect.c, 1.14, 1.15 app_test.c, 1.13, 1.14 app_transfer.c, 1.15, 1.16 app_txtcidname.c, 1.19, 1.20 app_url.c, 1.12, 1.13 app_userevent.c, 1.8, 1.9 app_verbose.c, 1.7, 1.8 app_voicemail.c, 1.252, 1.253 app_waitforring.c, 1.8, 1.9 app_waitforsilence.c, 1.10, 1.11 app_while.c, 1.11, 1.12 app_zapateller.c, 1.11, 1.12 app_zapbarge.c, 1.11, 1.12 app_zapras.c, 1.14, 1.15

russell russell
Wed Oct 19 14:25:17 CDT 2005


Update of /usr/cvsroot/asterisk/apps
In directory mongoose.digium.com:/tmp/cvs-serv15294/apps

Modified Files:
	app_adsiprog.c app_alarmreceiver.c app_authenticate.c 
	app_cdr.c app_chanisavail.c app_chanspy.c 
	app_controlplayback.c app_curl.c app_cut.c app_db.c app_dial.c 
	app_dictate.c app_directed_pickup.c app_directory.c app_disa.c 
	app_dumpchan.c app_enumlookup.c app_eval.c app_externalivr.c 
	app_festival.c app_groupcount.c app_hasnewvoicemail.c 
	app_ices.c app_image.c app_intercom.c app_ivrdemo.c 
	app_macro.c app_math.c app_md5.c app_meetme.c app_milliwatt.c 
	app_mp3.c app_muxmon.c app_nbscat.c app_osplookup.c app_page.c 
	app_parkandannounce.c app_playback.c app_queue.c app_random.c 
	app_read.c app_readfile.c app_realtime.c app_record.c 
	app_senddtmf.c app_sendtext.c app_setcallerid.c 
	app_setcdruserfield.c app_setcidname.c app_setcidnum.c 
	app_setrdnis.c app_settransfercapability.c app_skel.c 
	app_sms.c app_softhangup.c app_sql_postgres.c app_striplsd.c 
	app_substring.c app_system.c app_talkdetect.c app_test.c 
	app_transfer.c app_txtcidname.c app_url.c app_userevent.c 
	app_verbose.c app_voicemail.c app_waitforring.c 
	app_waitforsilence.c app_while.c app_zapateller.c 
	app_zapbarge.c app_zapras.c 
Log Message:
Massive cleanups to applications for LOCAL_USER handling and some other things.
In general, LOCAL_USER_ADD/REMOVE should be the first/last thing called in an
application.  An exception is if there is some *fast* setup code that might
halt the execution of the application, such as checking to see if an argument
exists.


Index: app_adsiprog.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_adsiprog.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- app_adsiprog.c	18 Oct 2005 22:52:21 -0000	1.16
+++ app_adsiprog.c	19 Oct 2005 18:19:01 -0000	1.17
@@ -1553,9 +1553,12 @@
 {
 	int res=0;
 	struct localuser *u;
+
+	LOCAL_USER_ADD(u);
+	
 	if (!data || ast_strlen_zero(data))
 		data = "asterisk.adsi";
-	LOCAL_USER_ADD(u);
+	
 	if (!adsi_available(chan)) {
 		if (option_verbose > 2)
 			ast_verbose(VERBOSE_PREFIX_3 "ADSI Unavailable on CPE.  Not bothering to try.\n");
@@ -1564,7 +1567,9 @@
 			ast_verbose(VERBOSE_PREFIX_3 "ADSI Available on CPE.  Attempting Upload.\n");
 		res = adsi_prog(chan, data);
 	}
+
 	LOCAL_USER_REMOVE(u);
+	
 	return res;
 }
 

Index: app_alarmreceiver.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_alarmreceiver.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- app_alarmreceiver.c	18 Oct 2005 22:52:21 -0000	1.16
+++ app_alarmreceiver.c	19 Oct 2005 18:19:01 -0000	1.17
@@ -652,11 +652,13 @@
 
 	if (ast_set_write_format(chan,AST_FORMAT_ULAW)){
 		ast_log(LOG_WARNING, "AlarmReceiver: Unable to set write format to Mu-law on %s\n",chan->name);
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 	
 	if (ast_set_read_format(chan,AST_FORMAT_ULAW)){
 		ast_log(LOG_WARNING, "AlarmReceiver: Unable to set read format to Mu-law on %s\n",chan->name);
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 

Index: app_authenticate.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_authenticate.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- app_authenticate.c	18 Oct 2005 22:52:21 -0000	1.16
+++ app_authenticate.c	19 Oct 2005 18:19:01 -0000	1.17
@@ -85,11 +85,14 @@
 	char passwd[256];
 	char *opts;
 	char *prompt;
+	
 	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "Authenticate requires an argument(password)\n");
 		return -1;
 	}
+	
 	LOCAL_USER_ADD(u);
+
 	if (chan->_state != AST_STATE_UP) {
 		res = ast_answer(chan);
 		if (res) {
@@ -97,6 +100,7 @@
 			return -1;
 		}
 	}
+	
 	strncpy(password, data, sizeof(password) - 1);
 	opts=strchr(password, '|');
 	if (opts) {

Index: app_cdr.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_cdr.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- app_cdr.c	18 Oct 2005 22:52:21 -0000	1.8
+++ app_cdr.c	19 Oct 2005 18:19:01 -0000	1.9
@@ -46,10 +46,17 @@
 
 static int nocdr_exec(struct ast_channel *chan, void *data)
 {
+	struct localuser *u;
+	
+	LOCAL_USER_ADD(u);
+
 	if (chan->cdr) {
 		ast_cdr_free(chan->cdr);
 		chan->cdr = NULL;
 	}
+
+	LOCAL_USER_REMOVE(u);
+
 	return 0;
 }
 

Index: app_chanisavail.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_chanisavail.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- app_chanisavail.c	18 Oct 2005 22:52:21 -0000	1.23
+++ app_chanisavail.c	19 Oct 2005 18:19:01 -0000	1.24
@@ -72,16 +72,17 @@
 	int res=-1, inuse=-1, option_state=0;
 	int status;
 	struct localuser *u;
-	char info[512], tmp[512], trychan[512], *peers, *tech, *number, *rest, *cur, *options, *stringp;
+	char *info, tmp[512], trychan[512], *peers, *tech, *number, *rest, *cur, *options, *stringp;
 	struct ast_channel *tempchan;
 
-	if (!data) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "ChanIsAvail requires an argument (Zap/1&Zap/2)\n");
 		return -1;
 	}
+
 	LOCAL_USER_ADD(u);
 
-	strncpy(info, (char *)data, sizeof(info)-1);
+	info = ast_strdupa(data); 
 	stringp = info;
 	strsep(&stringp, "|");
 	options = strsep(&stringp, "|");

Index: app_chanspy.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_chanspy.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- app_chanspy.c	18 Oct 2005 22:52:21 -0000	1.26
+++ app_chanspy.c	19 Oct 2005 18:19:01 -0000	1.27
@@ -540,24 +540,26 @@
 		return -1;
 	}
 
+	LOCAL_USER_ADD(u);
+
 	oldrf = chan->readformat;
 	oldwf = chan->writeformat;
 	if (ast_set_read_format(chan, AST_FORMAT_SLINEAR) < 0) {
 		ast_log(LOG_ERROR, "Could Not Set Read Format.\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 	
 	if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
 		ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
-	LOCAL_USER_ADD(u);
 	ast_answer(chan);
 
 	ast_set_flag(chan, AST_FLAG_SPYING); /* so nobody can spy on us while we are spying */
 
-
 	if ((argc = ast_separate_app_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
 		spec = argv[0];
 		if ( argc > 1) {

Index: app_controlplayback.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_controlplayback.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- app_controlplayback.c	18 Oct 2005 22:52:21 -0000	1.14
+++ app_controlplayback.c	19 Oct 2005 18:19:01 -0000	1.15
@@ -81,12 +81,14 @@
 		arg_pause = 5,
 		arg_restart = 6,
 	};
-
-	if (!data || ast_strlen_zero((char *)data)) {
+	
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
 		return -1;
 	}
 
+	LOCAL_USER_ADD(u);
+	
 	tmp = ast_strdupa(data);
 	memset(argv, 0, sizeof(argv));
 
@@ -94,6 +96,7 @@
 
 	if (argc < 1) {
 		ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
@@ -112,12 +115,8 @@
 	if (argv[arg_restart] && !is_on_phonepad(*argv[arg_restart]))
 		argv[arg_restart] = NULL;
 
-	LOCAL_USER_ADD(u);
-
 	res = ast_control_streamfile(chan, argv[arg_file], argv[arg_fwd], argv[arg_rev], argv[arg_stop], argv[arg_pause], argv[arg_restart], skipms);
 
-	LOCAL_USER_REMOVE(u);
-	
 	/* If we stopped on one of our stop keys, return 0  */
 	if (argv[arg_stop] && strchr(argv[arg_stop], res)) 
 		res = 0;
@@ -127,6 +126,8 @@
 			res = 0;
 	}
 
+	LOCAL_USER_REMOVE(u);
+
 	return res;
 }
 

Index: app_curl.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_curl.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- app_curl.c	18 Oct 2005 22:52:21 -0000	1.12
+++ app_curl.c	19 Oct 2005 18:19:01 -0000	1.13
@@ -118,27 +118,28 @@
 	char *info, *post_data=NULL, *url;
 	struct MemoryStruct chunk = { NULL, 0 };
 	static int dep_warning = 0;
-
-	if (!data || !strlen((char *)data)) {
-		ast_log(LOG_WARNING, "Curl requires an argument (URL)\n");
-		return -1;
-	}
-
+	
 	if (!dep_warning) {
 		ast_log(LOG_WARNING, "The application Curl is deprecated.  Please use the CURL() function instead.\n");
 		dep_warning = 1;
 	}
 
+	if (!data || ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "Curl requires an argument (URL)\n");
+		return -1;
+	}
+	
+	LOCAL_USER_ADD(u);
+	
 	if ((info = ast_strdupa((char *)data))) {
 		url = strsep(&info, "|");
 		post_data = info;
 	} else {
 		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
-	LOCAL_USER_ADD(u);
-
 	if (! curl_internal(&chunk, url, post_data)) {
 		if (chunk.memory) {
 			chunk.memory[chunk.size] = '\0';
@@ -164,23 +165,25 @@
 	char *info, *post_data=NULL, *url;
 	struct MemoryStruct chunk = { NULL, 0 };
 
-	if (!data || !strlen((char *)data)) {
+	*buf = '\0';
+	
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "CURL requires an argument (URL)\n");
-		*buf = '\0';
 		return buf;
 	}
 
-	if ((info = ast_strdupa((char *)data))) {
-		url = strsep(&info, "|");
-		post_data = info;
-	} else {
+	LOCAL_USER_ACF_ADD(u);
+
+	info = ast_strdupa(data);
+	if (!info) {
 		ast_log(LOG_ERROR, "Out of memory\n");
-		*buf = '\0';
+		LOCAL_USER_REMOVE(u);
 		return buf;
 	}
-
-	LOCAL_USER_ACF_ADD(u);
-
+	
+	url = strsep(&info, "|");
+	post_data = info;
+	
 	if (! curl_internal(&chunk, url, post_data)) {
 		if (chunk.memory) {
 			chunk.memory[chunk.size] = '\0';
@@ -192,7 +195,6 @@
 		}
 	} else {
 		ast_log(LOG_ERROR, "Cannot allocate curl structure\n");
-		*buf = '\0';
 	}
 
 	LOCAL_USER_REMOVE(u);

Index: app_cut.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_cut.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- app_cut.c	18 Oct 2005 22:52:21 -0000	1.15
+++ app_cut.c	19 Oct 2005 18:19:01 -0000	1.16
@@ -262,7 +262,6 @@
 	char *varname, *strings, result[512] = "";
 	static int dep_warning=0;
 
-	LOCAL_USER_ADD(u);
 	if (!dep_warning) {
 		ast_log(LOG_WARNING, "The application Sort is deprecated.  Please use the SORT() function instead.\n");
 		dep_warning=1;
@@ -270,10 +269,11 @@
 
 	if (!data) {
 		ast_log(LOG_ERROR, "Sort() requires an argument\n");
-		LOCAL_USER_REMOVE(u);
 		return 0;
 	}
 
+	LOCAL_USER_ADD(u);
+
 	strings = ast_strdupa((char *)data);
 	if (!strings) {
 		ast_log(LOG_ERROR, "Out of memory\n");

Index: app_db.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_db.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- app_db.c	18 Oct 2005 22:52:21 -0000	1.14
+++ app_db.c	19 Oct 2005 18:19:01 -0000	1.15
@@ -77,22 +77,24 @@
 
 static int deltree_exec(struct ast_channel *chan, void *data)
 {
-	int arglen;
 	char *argv, *family, *keytree;
+	struct localuser *u;
 
-	arglen = strlen(data);
-	argv = alloca(arglen + 1);
-	if (!argv) {	/* Why would this fail? */
-		ast_log(LOG_DEBUG, "Memory allocation failed\n");
+	LOCAL_USER_ADD(u);
+
+	argv = ast_strdupa(data);
+	if (!argv) {
+		ast_log(LOG_ERROR, "Memory allocation failed\n");
+		LOCAL_USER_REMOVE(u);
 		return 0;
 	}
-	memcpy(argv, data, arglen + 1);
 
 	if (strchr(argv, '/')) {
 		family = strsep(&argv, "/");
 		keytree = strsep(&argv, "\0");
 			if (!family || !keytree) {
 				ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n");
+				LOCAL_USER_REMOVE(u);
 				return 0;
 			}
 		if (!strlen(keytree))
@@ -114,27 +116,31 @@
 			ast_verbose(VERBOSE_PREFIX_3 "DBdeltree: Error deleting key from database.\n");
 	}
 
+	LOCAL_USER_REMOVE(u);
+
 	return 0;
 }
 
 static int del_exec(struct ast_channel *chan, void *data)
 {
-	int arglen;
 	char *argv, *family, *key;
+	struct localuser *u;
 
-	arglen = strlen(data);
-	argv = alloca(arglen + 1);
-	if (!argv) {	/* Why would this fail? */
-		ast_log (LOG_DEBUG, "Memory allocation failed\n");
+	LOCAL_USER_ADD(u);
+
+	argv = ast_strdupa(data);
+	if (!argv) {
+		ast_log (LOG_ERROR, "Memory allocation failed\n");
+		LOCAL_USER_REMOVE(u);
 		return 0;
 	}
-	memcpy(argv, data, arglen + 1);
 
 	if (strchr(argv, '/')) {
 		family = strsep(&argv, "/");
 		key = strsep(&argv, "\0");
 		if (!family || !key) {
 			ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n");
+			LOCAL_USER_REMOVE(u);
 			return 0;
 		}
 		if (option_verbose > 2)
@@ -146,27 +152,31 @@
 	} else {
 		ast_log(LOG_DEBUG, "Ignoring, no parameters\n");
 	}
+
+	LOCAL_USER_REMOVE(u);
+	
 	return 0;
 }
 
 static int put_exec(struct ast_channel *chan, void *data)
 {
-	int arglen;
 	char *argv, *value, *family, *key;
 	static int dep_warning = 0;
+	struct localuser *u;
+
+	LOCAL_USER_ADD(u);
 
 	if (!dep_warning) {
 		ast_log(LOG_WARNING, "This application has been deprecated, please use the ${DB(family/key)} function instead.\n");
 		dep_warning = 1;
 	}
 	
-	arglen = strlen(data);
-	argv = alloca(arglen + 1);
-	if (!argv) {	/* Why would this fail? */
-		ast_log(LOG_DEBUG, "Memory allocation failed\n");
+	argv = ast_strdupa(data);
+	if (!argv) {
+		ast_log(LOG_ERROR, "Memory allocation failed\n");
+		LOCAL_USER_REMOVE(u);
 		return 0;
 	}
-	memcpy(argv, data, arglen + 1);
 
 	if (strchr(argv, '/') && strchr(argv, '=')) {
 		family = strsep(&argv, "/");
@@ -174,6 +184,7 @@
 		value = strsep(&argv, "\0");
 		if (!value || !family || !key) {
 			ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n");
+			LOCAL_USER_REMOVE(u);
 			return 0;
 		}
 		if (option_verbose > 2)
@@ -186,28 +197,32 @@
 	} else	{
 		ast_log (LOG_DEBUG, "Ignoring, no parameters\n");
 	}
+
+	LOCAL_USER_REMOVE(u);
+
 	return 0;
 }
 
 static int get_exec(struct ast_channel *chan, void *data)
 {
-	int arglen;
 	char *argv, *varname, *family, *key;
 	char dbresult[256];
 	static int dep_warning = 0;
+	struct localuser *u;
+
+	LOCAL_USER_ADD(u);
 
 	if (!dep_warning) {
 		ast_log(LOG_WARNING, "This application has been deprecated, please use the ${DB(family/key)} function instead.\n");
 		dep_warning = 1;
 	}
 	
-	arglen = strlen(data);
-	argv = alloca(arglen + 1);
-	if (!argv) {	/* Why would this fail? */
-		ast_log(LOG_DEBUG, "Memory allocation failed\n");
+	argv = ast_strdupa(data);
+	if (!argv) {
+		ast_log(LOG_ERROR, "Memory allocation failed\n");
+		LOCAL_USER_REMOVE(u);
 		return 0;
 	}
-	memcpy(argv, data, arglen + 1);
 
 	if (strchr(argv, '=') && strchr(argv, '/')) {
 		varname = strsep(&argv, "=");
@@ -215,6 +230,7 @@
 		key = strsep(&argv, "\0");
 		if (!varname || !family || !key) {
 			ast_log(LOG_DEBUG, "Ignoring; Syntax error in argument\n");
+			LOCAL_USER_REMOVE(u);
 			return 0;
 		}
 		if (option_verbose > 2)
@@ -227,13 +243,14 @@
 			if (option_verbose > 2)
 			ast_verbose(VERBOSE_PREFIX_3 "DBget: Value not found in database.\n");
 			/* Send the call to n+101 priority, where n is the current priority */
-			if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num))
-				chan->priority += 100;
+			ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
 		}
-
 	} else {
 		ast_log(LOG_DEBUG, "Ignoring, no parameters\n");
 	}
+
+	LOCAL_USER_REMOVE(u);
+
 	return 0;
 }
 
@@ -256,12 +273,10 @@
 	int retval;
 
 	retval = ast_register_application(g_app, get_exec, g_synopsis, g_descrip);
-	if (!retval)
-		retval = ast_register_application(p_app, put_exec, p_synopsis, p_descrip);
-	if (!retval)
-		retval = ast_register_application(d_app, del_exec, d_synopsis, d_descrip);
-	if (!retval)
-		retval = ast_register_application(dt_app, deltree_exec, dt_synopsis, dt_descrip);
+	retval |= ast_register_application(p_app, put_exec, p_synopsis, p_descrip);
+	retval |= ast_register_application(d_app, del_exec, d_synopsis, d_descrip);
+	retval |= ast_register_application(dt_app, deltree_exec, dt_synopsis, dt_descrip);
+	
 	return retval;
 }
 

Index: app_dial.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_dial.c,v
retrieving revision 1.171
retrieving revision 1.172
diff -u -d -r1.171 -r1.172
--- app_dial.c	18 Oct 2005 22:52:21 -0000	1.171
+++ app_dial.c	19 Oct 2005 18:19:01 -0000	1.172
@@ -692,20 +692,22 @@
 	char *dblgoto = NULL;
 	int priority_jump = 0;
 
-	if (!data) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "Dial requires an argument (technology1/number1&technology2/number2...|optional timeout|options)\n");
 		return -1;
 	}
 
-	if (!(info = ast_strdupa(data))) {
+	LOCAL_USER_ADD(u);
+
+	info = ast_strdupa(data);	
+	if (!info) {
 		ast_log(LOG_WARNING, "Unable to dupe data :(\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
-	LOCAL_USER_ADD(u);
 	
 	peers = info;
 	if (peers) {
-		
 		timeout = strchr(info, '|');
 		if (timeout) {
 			*timeout = '\0';
@@ -1644,6 +1646,7 @@
 			if (res < 0) {
 				ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", chan->name, peer->name);
 				ast_hangup(peer);
+				LOCAL_USER_REMOVE(u);
 				return -1;
 			}
 			res = ast_bridge_call(chan,peer,&config);
@@ -1674,11 +1677,11 @@
 	pbx_builtin_setvar_helper(chan, "DIALSTATUS", status);
 	ast_log(LOG_DEBUG, "Exiting with DIALSTATUS=%s.\n", status);
 	
-	LOCAL_USER_REMOVE(u);
-	
 	if ((ast_test_flag(peerflags, DIAL_GO_ON)) && (!chan->_softhangup) && (res != AST_PBX_KEEPALIVE))
-	    res=0;
-	    
+		res=0;
+	
+	LOCAL_USER_REMOVE(u);    
+	
 	return res;
 }
 
@@ -1693,19 +1696,25 @@
 {
 	char *announce = NULL, *context = NULL, *dialdata = NULL;
 	int sleep = 0, loops = 0, res = 0;
-	struct localuser *u = NULL;
+	struct localuser *u;
 	struct ast_flags peerflags;
 	
-	memset(&peerflags, 0, sizeof(peerflags));
+	if (!data || ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "RetryDial requires an argument!\n");
+		return -1;
+	}	
 
 	LOCAL_USER_ADD(u);
-	
-	if (!data || !(announce = ast_strdupa(data))) {
+
+	announce = ast_strdupa(data);	
+	if (!announce) {	
 		ast_log(LOG_ERROR, "Out of memory!\n");
 		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 	
+	memset(&peerflags, 0, sizeof(peerflags));
+
 	if ((dialdata = strchr(announce, '|'))) {
 		*dialdata = '\0';
 		dialdata++;

Index: app_dictate.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_dictate.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- app_dictate.c	18 Oct 2005 22:52:21 -0000	1.6
+++ app_dictate.c	19 Oct 2005 18:19:01 -0000	1.7
@@ -98,7 +98,8 @@
 		maxlen = 0,
 		mode = 0;
 		
-
+	LOCAL_USER_ADD(u);
+	
 	snprintf(dftbase, sizeof(dftbase), "%s/dictate", ast_config_AST_SPOOL_DIR);
 	if (data && !ast_strlen_zero(data) && (mydata = ast_strdupa(data))) {
 		argc = ast_separate_app_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
@@ -113,10 +114,10 @@
 	oldr = chan->readformat;
 	if ((res = ast_set_read_format(chan, AST_FORMAT_SLINEAR)) < 0) {
 		ast_log(LOG_WARNING, "Unable to set to linear mode.\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
-	LOCAL_USER_ADD(u);
 	ast_answer(chan);
 	ast_safe_sleep(chan, 200);
 	for(res = 0; !res;) {

Index: app_directed_pickup.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_directed_pickup.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- app_directed_pickup.c	18 Oct 2005 22:52:21 -0000	1.4
+++ app_directed_pickup.c	19 Oct 2005 18:19:01 -0000	1.5
@@ -57,6 +57,13 @@
 	char *tmp = NULL, *exten = NULL, *context = NULL;
 	char workspace[256] = "";
 
+	if (!data || ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "Pickup requires an argument (extension) !\n");
+		return -1;	
+	}
+
+	LOCAL_USER_ADD(u);
+	
 	/* Get the extension and context if present */
 	exten = data;
 	context = strchr(data, '@');
@@ -65,14 +72,6 @@
 		context++;
 	}
 
-	/* Make sure we atleast have an extension to work with */
-	if (!exten) {
-		ast_log(LOG_WARNING, "%s requires atleast one argument (extension)\n", app);
-		return -1;
-	}
-
-	LOCAL_USER_ADD(u);
-
 	/* Find a channel to pickup */
 	origin = ast_get_channel_by_exten_locked(exten, context);
 	if (origin) {
@@ -121,7 +120,9 @@
 	}
 	/* Done */
  out:
-	if (target) ast_mutex_unlock(&target->lock);
+	if (target) 
+		ast_mutex_unlock(&target->lock);
+	
 	LOCAL_USER_REMOVE(u);
 
 	return res;

Index: app_directory.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_directory.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- app_directory.c	18 Oct 2005 22:52:21 -0000	1.46
+++ app_directory.c	19 Oct 2005 18:19:01 -0000	1.47
@@ -410,11 +410,13 @@
 	int last = 1;
 	char *context, *dialcontext, *dirintro, *options;
 
-	if (!data) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "Directory requires an argument (context[,dialcontext])\n");
 		return -1;
 	}
 
+	LOCAL_USER_ADD(u);
+
 	context = ast_strdupa(data);
 	dialcontext = strchr(context, '|');
 	if (dialcontext) {
@@ -431,10 +433,10 @@
 		dialcontext = context;
 
 	cfg = realtime_directory(context);
-	if (!cfg)
+	if (!cfg) {
+		LOCAL_USER_REMOVE(u);
 		return -1;
-
-	LOCAL_USER_ADD(u);
+	}
 
 	dirintro = ast_variable_retrieve(cfg, context, "directoryintro");
 	if (!dirintro || ast_strlen_zero(dirintro))

Index: app_disa.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_disa.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- app_disa.c	18 Oct 2005 22:52:21 -0000	1.35
+++ app_disa.c	19 Oct 2005 18:19:01 -0000	1.36
@@ -120,7 +120,7 @@
 	int firstdigittimeout = 20000;
 	int digittimeout = 10000;
 	struct localuser *u;
-	char tmp[256],arg2[256]="",exten[AST_MAX_EXTENSION],acctcode[20]="";
+	char *tmp, arg2[256]="",exten[AST_MAX_EXTENSION],acctcode[20]="";
 	char *ourcontext,*ourcallerid,ourcidname[256],ourcidnum[256],*mailbox;
 	struct ast_frame *f;
 	struct timeval lastdigittime;
@@ -129,28 +129,39 @@
 	FILE *fp;
 	char *stringp=NULL;
 
+	if (!data || ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "disa requires an argument (passcode/passcode file)\n");
+		return -1;
+	}
+
+	LOCAL_USER_ADD(u);
+	
 	if (chan->pbx) {
 		firstdigittimeout = chan->pbx->rtimeout*1000;
 		digittimeout = chan->pbx->dtimeout*1000;
 	}
 	
-	if (ast_set_write_format(chan,AST_FORMAT_ULAW))
-	{
+	if (ast_set_write_format(chan,AST_FORMAT_ULAW)) {
 		ast_log(LOG_WARNING, "Unable to set write format to Mu-law on %s\n",chan->name);
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
-	if (ast_set_read_format(chan,AST_FORMAT_ULAW))
-	{
+	if (ast_set_read_format(chan,AST_FORMAT_ULAW)) {
 		ast_log(LOG_WARNING, "Unable to set read format to Mu-law on %s\n",chan->name);
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
-	if (!data || !strlen((char *)data)) {
-		ast_log(LOG_WARNING, "disa requires an argument (passcode/passcode file)\n");
-		return -1;
-	}
+	
 	ast_log(LOG_DEBUG, "Digittimeout: %d\n", digittimeout);
 	ast_log(LOG_DEBUG, "Responsetimeout: %d\n", firstdigittimeout);
-	strncpy(tmp, (char *)data, sizeof(tmp)-1);
+
+	tmp = ast_strdupa(data);
+	if (!tmp) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}	
+
 	stringp=tmp;
 	strsep(&stringp, "|");
 	ourcontext = strsep(&stringp, "|");
@@ -169,9 +180,8 @@
 	if (!mailbox)
 		mailbox = "";
 	ast_log(LOG_DEBUG, "Mailbox: %s\n",mailbox);
-	LOCAL_USER_ADD(u);
-	if (chan->_state != AST_STATE_UP)
-	{
+	
+	if (chan->_state != AST_STATE_UP) {
 		/* answer */
 		ast_answer(chan);
 	}
@@ -183,8 +193,7 @@
 
 	ast_log(LOG_DEBUG, "Context: %s\n",ourcontext);
 
-	if (!strcasecmp(tmp, "no-password"))
-	{;
+	if (!strcasecmp(tmp, "no-password")) {
 		k |= 1; /* We have the password */
 		ast_log(LOG_DEBUG, "DISA no-password login success\n");
 	}
@@ -192,8 +201,7 @@
 
 	play_dialtone(chan, mailbox);
 
-	for(;;)
-	{
+	for (;;) {
 		  /* if outa time, give em reorder */
 		if (ast_tvdiff_ms(ast_tvnow(), lastdigittime) > 
 		    ((k&2) ? digittimeout : firstdigittimeout))

Index: app_dumpchan.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_dumpchan.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- app_dumpchan.c	18 Oct 2005 22:52:21 -0000	1.11
+++ app_dumpchan.c	19 Oct 2005 18:19:01 -0000	1.12
@@ -138,9 +138,10 @@
 	char info[1024];
 	int level = 0;
 	static char *line = "================================================================================";
+	
 	LOCAL_USER_ADD(u);
 
-	if (data) {
+	if (data && !ast_strlen_zero(data)) {
 		level = atoi(data);
 	}
 
@@ -150,6 +151,7 @@
 		ast_verbose("\nDumping Info For Channel: %s:\n%s\nInfo:\n%s\nVariables:\n%s%s\n",chan->name, line, info, vars, line);
 
 	LOCAL_USER_REMOVE(u);
+	
 	return res;
 }
 

Index: app_enumlookup.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_enumlookup.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- app_enumlookup.c	18 Oct 2005 22:52:21 -0000	1.22
+++ app_enumlookup.c	19 Oct 2005 18:19:01 -0000	1.23
@@ -85,27 +85,27 @@
 	static int dep_warning=0;
 	struct localuser *u;
 
+	if (!data || ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "EnumLookup requires an argument (extension)\n");
+		return -1;
+	}
+		
 	if (!dep_warning) {
 		ast_log(LOG_WARNING, "The application EnumLookup is deprecated.  Please use the ENUMLOOKUP() function instead.\n");
-		dep_warning=1;
+		dep_warning = 1;
 	}
 
+	LOCAL_USER_ADD(u);
+
 	tech[0] = '\0';
 
-	if (!data || ast_strlen_zero(data)) {
-		ast_log(LOG_WARNING, "EnumLookup requires an argument (extension)\n");
-		res = 0;
-	}
-	LOCAL_USER_ADD(u);
-	if (!res) {
-               res = ast_get_enum(chan, data, dest, sizeof(dest), tech, sizeof(tech), NULL, NULL);
-		printf("ENUM got '%d'\n", res);
-	}
-	LOCAL_USER_REMOVE(u);
+	res = ast_get_enum(chan, data, dest, sizeof(dest), tech, sizeof(tech), NULL, NULL);
+	
 	if (!res) {	/* Failed to do a lookup */
 		/* Look for a "busy" place */
 		ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
 		pbx_builtin_setvar_helper(chan, "ENUMSTATUS", "ERROR");
+		LOCAL_USER_REMOVE(u);
 		return 0;
 	}
 	pbx_builtin_setvar_helper(chan, "ENUMSTATUS", tech);
@@ -167,6 +167,9 @@
 			res = 0;
 		}
 	}
+
+	LOCAL_USER_REMOVE(u);
+
 	return 0;
 }
 

Index: app_eval.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_eval.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- app_eval.c	18 Oct 2005 22:52:21 -0000	1.8
+++ app_eval.c	19 Oct 2005 18:19:01 -0000	1.9
@@ -64,13 +64,13 @@
 	char *s, *newvar=NULL, tmp[MAXRESULT];
 	static int dep_warning = 0;
 
+	LOCAL_USER_ADD(u);
+	
 	if (!dep_warning) {
 		ast_log(LOG_WARNING, "This application has been deprecated in favor of the dialplan function, EVAL\n");
 		dep_warning = 1;
 	}
 
-	LOCAL_USER_ADD(u);
-
 	/* Check and parse arguments */
 	if (data) {
 		s = ast_strdupa((char *)data);

Index: app_externalivr.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_externalivr.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- app_externalivr.c	18 Oct 2005 22:52:21 -0000	1.10
+++ app_externalivr.c	19 Oct 2005 18:19:01 -0000	1.11
@@ -256,6 +256,12 @@
 	FILE *child_errors = NULL;
 	FILE *child_events = NULL;
 
+	LOCAL_USER_ADD(u);
+	
+	AST_LIST_HEAD_INIT(&u->playlist);
+	AST_LIST_HEAD_INIT(&u->finishlist);
+	u->abort_current_sound = 0;
+	
 	if (!args || ast_strlen_zero(args)) {
 		ast_log(LOG_WARNING, "ExternalIVR requires a command to execute\n");
 		goto exit;
@@ -268,8 +274,6 @@
 	while ((argc < 31) && (argv[argc++] = strsep(&buf, "|")));
 	argv[argc] = NULL;
 
-	LOCAL_USER_ADD(u);
-
 	if (pipe(child_stdin)) {
 		ast_chan_log(LOG_WARNING, chan, "Could not create pipe for child input: %s\n", strerror(errno));
 		goto exit;
@@ -285,10 +289,6 @@
 		goto exit;
 	}
 
-	u->abort_current_sound = 0;
-	AST_LIST_HEAD_INIT(&u->playlist);
-	AST_LIST_HEAD_INIT(&u->finishlist);
-
 	if (chan->_state != AST_STATE_UP) {
 		ast_answer(chan);
 	}
@@ -533,12 +533,10 @@
 	if (child_stderr[1])
 		close(child_stderr[1]);
 
-	if (u) {
-		while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list)))
-			free(entry);
+	while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list)))
+		free(entry);
 
-		LOCAL_USER_REMOVE(u);
-	}
+	LOCAL_USER_REMOVE(u);
 
 	return res;
 }

Index: app_festival.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_festival.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- app_festival.c	18 Oct 2005 22:52:21 -0000	1.34
+++ app_festival.c	19 Oct 2005 18:19:01 -0000	1.35
@@ -292,13 +292,21 @@
 	int fdesc = -1;
 	char buffer[16384];
 	int seekpos = 0;	
-	char data[256] = "";
+	char *data;	
 	char *intstr;
-	
 	struct ast_config *cfg;
+
+	if (!vdata || ast_strlen_zero(vdata)) {
+		ast_log(LOG_WARNING, "festival requires an argument (text)\n");
+		return -1;
+	}
+
+	LOCAL_USER_ADD(u);
+
 	cfg = ast_config_load(FESTIVAL_CONFIG);
 	if (!cfg) {
 		ast_log(LOG_WARNING, "No such configuration file %s\n", FESTIVAL_CONFIG);
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 	if (!(host = ast_variable_retrieve(cfg, "general", "host"))) {
@@ -320,19 +328,23 @@
 	if (!(festivalcommand = ast_variable_retrieve(cfg, "general", "festivalcommand"))) {
 		festivalcommand = "(tts_textasterisk \"%s\" 'file)(quit)\n";
 	}
-	if (!vdata || ast_strlen_zero(vdata)) {
-		ast_log(LOG_WARNING, "festival requires an argument (text)\n");
+	
+	data = ast_strdupa(vdata);
+	if (!data) {
+		ast_log(LOG_ERROR, "Out of memery\n");
 		ast_config_destroy(cfg);
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
-	strncpy(data, vdata, sizeof(data) - 1);
-	if ((intstr = strchr(data, '|'))) {
+
+	intstr = strchr(data, '|');
+	if (intstr) {	
 		*intstr = '\0';
 		intstr++;
 		if (!strcasecmp(intstr, "any"))
 			intstr = AST_DIGIT_ANY;
 	}
-	LOCAL_USER_ADD(u);
+	
 	ast_log(LOG_DEBUG, "Text passed to festival server : %s\n",(char *)data);
 	/* Connect to local festival server */
 	
@@ -341,6 +353,7 @@
     	if (fd < 0) {
 		ast_log(LOG_WARNING,"festival_client: can't get socket\n");
 		ast_config_destroy(cfg);
+		LOCAL_USER_REMOVE(u);
         	return -1;
 	}
         memset(&serv_addr, 0, sizeof(serv_addr));
@@ -350,6 +363,7 @@
 	        if (serverhost == (struct hostent *)0) {
         	    	ast_log(LOG_WARNING,"festival_client: gethostbyname failed\n");
 			ast_config_destroy(cfg);
+			LOCAL_USER_REMOVE(u);
 	            	return -1;
         	}
 	        memmove(&serv_addr.sin_addr,serverhost->h_addr, serverhost->h_length);
@@ -360,6 +374,7 @@
 	if (connect(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != 0) {
 		ast_log(LOG_WARNING,"festival_client: connect to server failed\n");
 		ast_config_destroy(cfg);
+		LOCAL_USER_REMOVE(u);
         	return -1;
     	}
     	
@@ -463,7 +478,7 @@
 	} while (strcmp(ack,"OK\n") != 0);
 	close(fd);
 	ast_config_destroy(cfg);
-	LOCAL_USER_REMOVE(u);                                                                                
+	LOCAL_USER_REMOVE(u);
 	return res;
 
 }

Index: app_groupcount.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_groupcount.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- app_groupcount.c	18 Oct 2005 22:52:21 -0000	1.22
+++ app_groupcount.c	19 Oct 2005 18:19:01 -0000	1.23
@@ -117,13 +117,13 @@
 	struct localuser *u;
 	static int deprecation_warning = 0;
 
+	LOCAL_USER_ADD(u);
+	
 	if (!deprecation_warning) {
 	        ast_log(LOG_WARNING, "The SetGroup application has been deprecated, please use the GROUP() function.\n");
 		deprecation_warning = 1;
 	}
 
-	LOCAL_USER_ADD(u);
-
 	if (ast_app_group_set_channel(chan, data))
 		ast_log(LOG_WARNING, "SetGroup requires an argument (group name)\n");
 
@@ -140,8 +140,6 @@
 	char category[80]="";
 	static int deprecation_warning = 0;
 
-	LOCAL_USER_ADD(u);
-
 	if (!deprecation_warning) {
 	        ast_log(LOG_WARNING, "The CheckGroup application has been deprecated, please use a combination of the GotoIf application and the GROUP_COUNT() function.\n");
 		deprecation_warning = 1;
@@ -152,6 +150,8 @@
 		return res;
 	}
 
+	LOCAL_USER_ADD(u);
+
   	ast_app_group_split_group(data, limit, sizeof(limit), category, sizeof(category));
 
  	if ((sscanf(limit, "%d", &max) == 1) && (max > -1)) {

Index: app_hasnewvoicemail.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_hasnewvoicemail.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- app_hasnewvoicemail.c	18 Oct 2005 22:52:21 -0000	1.18
+++ app_hasnewvoicemail.c	19 Oct 2005 18:19:02 -0000	1.19
@@ -94,24 +94,25 @@
 	int vmcount = 0;
 	static int dep_warning = 0;
 
+	if (!dep_warning) {
+		ast_log(LOG_WARNING, "The applications HasVoicemail and HasNewVoicemail have been deprecated.  Please use the VMCOUNT() function instead.\n");
+		dep_warning = 1;
+	}
+	
 	if (!data) {
 		ast_log(LOG_WARNING, "HasVoicemail requires an argument (vm-box[/folder][@context]|varname)\n");
 		return -1;
 	}
 
-	if (!dep_warning) {
-		ast_log(LOG_WARNING, "The applications HasVoicemail and HasNewVoicemail have been deprecated.  Please use the VMCOUNT() function instead.\n");
-		dep_warning = 1;
-	}
+	LOCAL_USER_ADD(u);
 
 	input = ast_strdupa((char *)data);
 	if (! input) {
 		ast_log(LOG_ERROR, "Out of memory error\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
-	LOCAL_USER_ADD(u);
-
 	temps = input;
 	if ((temps = strsep(&input, "|"))) {
 		if (input && !ast_strlen_zero(input))
@@ -158,11 +159,13 @@
 
 	LOCAL_USER_ACF_ADD(u);
 
+	buf[0] = '\0';
+
 	args = ast_strdupa(data);
 	if (!args) {
 		ast_log(LOG_ERROR, "Out of memory");
 		LOCAL_USER_REMOVE(u);
-		return "";
+		return buf;
 	}
 
 	box = strsep(&args, "|");
@@ -180,7 +183,9 @@
 	}
 
 	snprintf(buf, len, "%d", hasvoicemail_internal(context, box, folder));
+
 	LOCAL_USER_REMOVE(u);
+	
 	return buf;
 }
 

Index: app_ices.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_ices.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- app_ices.c	18 Oct 2005 22:52:21 -0000	1.9
+++ app_ices.c	19 Oct 2005 18:19:02 -0000	1.10
@@ -100,20 +100,24 @@
 	struct ast_frame *f;
 	char filename[256]="";
 	char *c;
-	last.tv_usec = 0;
-	last.tv_sec = 0;
-	if (!data || !strlen(data)) {
+
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "ICES requires an argument (configfile.xml)\n");
 		return -1;
 	}
+
+	LOCAL_USER_ADD(u);
+	
+	last = ast_tv(0, 0);
+	
 	if (pipe(fds)) {
 		ast_log(LOG_WARNING, "Unable to create pipe\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 	flags = fcntl(fds[1], F_GETFL);
 	fcntl(fds[1], F_SETFL, flags | O_NONBLOCK);
 	
-	LOCAL_USER_ADD(u);
 	ast_stopstream(chan);
 
 	if (chan->_state != AST_STATE_UP)
@@ -123,6 +127,7 @@
 		close(fds[0]);
 		close(fds[1]);
 		ast_log(LOG_WARNING, "Answer failed!\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
@@ -132,6 +137,7 @@
 		close(fds[0]);
 		close(fds[1]);
 		ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 	if (((char *)data)[0] == '/')
@@ -174,11 +180,14 @@
 		}
 	}
 	close(fds[1]);
-	LOCAL_USER_REMOVE(u);
+	
 	if (pid > -1)
 		kill(pid, SIGKILL);
 	if (!res && oreadformat)
 		ast_set_read_format(chan, oreadformat);
+
+	LOCAL_USER_REMOVE(u);
+
 	return res;
 }
 

Index: app_image.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_image.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- app_image.c	18 Oct 2005 22:52:21 -0000	1.9
+++ app_image.c	19 Oct 2005 18:19:02 -0000	1.10
@@ -61,14 +61,13 @@
 	int res = 0;
 	struct localuser *u;
 	
-	LOCAL_USER_ADD(u);
-
-	if (!data || !strlen((char *)data)) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "SendImage requires an argument (filename)\n");
-		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
+	LOCAL_USER_ADD(u);
+
 	if (!ast_supports_images(chan)) {
 		/* Does not support transport */
 		ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);

Index: app_intercom.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_intercom.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- app_intercom.c	18 Oct 2005 22:52:21 -0000	1.24
+++ app_intercom.c	19 Oct 2005 18:19:02 -0000	1.25
@@ -157,6 +157,7 @@
 	res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
 	if (res < 0) {
 		ast_log(LOG_WARNING, "Unable to set format to signed linear on channel %s\n", chan->name);
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 	/* Read packets from the channel */
@@ -184,9 +185,12 @@
 				res = -1;
 		}
 	}
-	LOCAL_USER_REMOVE(u);
+	
 	if (!res)
 		ast_set_read_format(chan, oreadformat);
+
+	LOCAL_USER_REMOVE(u);
+
 	return res;
 }
 

Index: app_ivrdemo.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_ivrdemo.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- app_ivrdemo.c	18 Oct 2005 22:52:21 -0000	1.9
+++ app_ivrdemo.c	19 Oct 2005 18:19:02 -0000	1.10
@@ -88,17 +88,23 @@
 {
 	int res=0;
 	struct localuser *u;
-	if (!data) {
+	
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "skel requires an argument (filename)\n");
 		return -1;
 	}
+	
 	LOCAL_USER_ADD(u);
+
 	/* Do our thing here */
+
 	if (chan->_state != AST_STATE_UP)
 		res = ast_answer(chan);
 	if (!res)
 		res = ast_ivr_menu_run(chan, &ivr_demo, data);
+	
 	LOCAL_USER_REMOVE(u);
+
 	return res;
 }
 

Index: app_macro.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_macro.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- app_macro.c	18 Oct 2005 22:52:21 -0000	1.29
+++ app_macro.c	19 Oct 2005 18:19:02 -0000	1.30
@@ -110,12 +110,14 @@
 	char *save_macro_priority;
 	char *save_macro_offset;
 	struct localuser *u;
-  
+ 
 	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "Macro() requires arguments. See \"show application macro\" for help.\n");
-		return 0;
+		return -1;
 	}
 
+	LOCAL_USER_ADD(u);
+
 	/* Count how many levels deep the rabbit hole goes */
 	tmp = pbx_builtin_getvar_helper(chan, "MACRO_DEPTH");
 	if (tmp) {
@@ -126,16 +128,18 @@
 
 	if (depth >= 7) {
 		ast_log(LOG_ERROR, "Macro():  possible infinite loop detected.  Returning early.\n");
+		LOCAL_USER_REMOVE(u);
 		return 0;
 	}
 	snprintf(depthc, sizeof(depthc), "%d", depth + 1);
 	pbx_builtin_setvar_helper(chan, "MACRO_DEPTH", depthc);
 
-	tmp = ast_strdupa((char *) data);
+	tmp = ast_strdupa(data);
 	rest = tmp;
 	macro = strsep(&rest, "|");
 	if (!macro || ast_strlen_zero(macro)) {
 		ast_log(LOG_WARNING, "Invalid macro name specified\n");
+		LOCAL_USER_REMOVE(u);
 		return 0;
 	}
 	snprintf(fullmacro, sizeof(fullmacro), "macro-%s", macro);
@@ -144,10 +148,10 @@
 			ast_log(LOG_WARNING, "No such context '%s' for macro '%s'\n", fullmacro, macro);
 		else
 	  		ast_log(LOG_WARNING, "Context '%s' for macro '%s' lacks 's' extension, priority 1\n", fullmacro, macro);
+		LOCAL_USER_REMOVE(u);
 		return 0;
 	}
-
-	LOCAL_USER_ADD(u);
+	
 	/* Save old info */
 	oldpriority = chan->priority;
 	ast_copy_string(oldexten, chan->exten, sizeof(oldexten));
@@ -305,24 +309,33 @@
 {
 	char *expr = NULL, *label_a = NULL, *label_b = NULL;
 	int res = 0;
+	struct localuser *u;
 
-	if((expr = ast_strdupa((char *) data))) {
-		if ((label_a = strchr(expr, '?'))) {
-			*label_a = '\0';
-			label_a++;
-			if ((label_b = strchr(label_a, ':'))) {
-				*label_b = '\0';
-				label_b++;
-			}
-			if (ast_true(expr))
-				macro_exec(chan, label_a);
-			else if (label_b) 
-				macro_exec(chan, label_b);
-			
-		} else
-			ast_log(LOG_WARNING, "Invalid Syntax.\n");
-	} else 
+	LOCAL_USER_ADD(u);
+
+	expr = ast_strdupa(data);
+	if (!expr) {
 		ast_log(LOG_ERROR, "Out of Memory!\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
+
+	if ((label_a = strchr(expr, '?'))) {
+		*label_a = '\0';
+		label_a++;
+		if ((label_b = strchr(label_a, ':'))) {
+			*label_b = '\0';
+			label_b++;
+		}
+		if (ast_true(expr))
+			macro_exec(chan, label_a);
+		else if (label_b) 
+			macro_exec(chan, label_b);
+	} else
+		ast_log(LOG_WARNING, "Invalid Syntax.\n");
+
+	LOCAL_USER_REMOVE(u);
+
 	return res;
 }
 			

Index: app_math.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_math.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- app_math.c	18 Oct 2005 22:52:21 -0000	1.14
+++ app_math.c	19 Oct 2005 18:19:02 -0000	1.15
@@ -108,14 +108,19 @@
 		deprecation_warning = 1;
 	}
 
-	if (!data) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "No parameters passed. !\n");
 		return -1;
 	}
 
 	LOCAL_USER_ADD(u);
-		
-	s = ast_strdupa((void *) data);
+
+	s = ast_strdupa(data);
+	if (!s) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
 
 	mvar = strsep(&s, "|");
 	mvalue1 = strsep(&s, "|");

Index: app_md5.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_md5.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- app_md5.c	18 Oct 2005 22:52:21 -0000	1.9
+++ app_md5.c	19 Oct 2005 18:19:02 -0000	1.10
@@ -72,11 +72,13 @@
 		dep_warning = 1;
 	}	
 
-	if (!data) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "Syntax: md5(<varname>=<string>) - missing argument!\n");
 		return -1;
 	}
+	
 	LOCAL_USER_ADD(u);
+
 	memset(retvar,0, sizeof(retvar));
 	string = ast_strdupa(data);
 	varname = strsep(&string,"=");
@@ -107,11 +109,13 @@
 		dep_warning = 1;
 	}
 	
-	if (!data) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "Syntax: MD5Check(<md5hash>,<string>) - missing argument!\n");
 		return -1;
 	}
+	
 	LOCAL_USER_ADD(u);
+	
 	memset(newhash,0, sizeof(newhash));
 
 	string = ast_strdupa(data);

Index: app_meetme.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_meetme.c,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -d -r1.113 -r1.114
--- app_meetme.c	18 Oct 2005 22:52:21 -0000	1.113
+++ app_meetme.c	19 Oct 2005 18:19:02 -0000	1.114
@@ -1667,8 +1667,16 @@
 		ast_log(LOG_WARNING, "MeetMeCount requires an argument (conference number)\n");
 		return -1;
 	}
-	localdata = ast_strdupa(data);
+
 	LOCAL_USER_ADD(u);
+	
+	localdata = ast_strdupa(data);
+	if (!localdata) {
+		ast_log(LOG_ERROR, "Out of memory!\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
+	
 	confnum = strsep(&localdata,"|");       
 	conf = find_conf(chan, confnum, 0, 0, NULL);
 	if (conf)
@@ -1704,17 +1712,19 @@
 	int always_prompt = 0;
 	char *notdata, *info, *inflags = NULL, *inpin = NULL, the_pin[AST_MAX_EXTENSION] = "";
 
+	LOCAL_USER_ADD(u);
+
 	if (!data || ast_strlen_zero(data)) {
 		allowretry = 1;
 		notdata = "";
 	} else {
 		notdata = data;
 	}
-	LOCAL_USER_ADD(u);
+	
 	if (chan->_state != AST_STATE_UP)
 		ast_answer(chan);
 
-	info = ast_strdupa((char *)notdata);
+	info = ast_strdupa(notdata);
 
 	if (info) {
 		char *tmp = strsep(&info, "|");
@@ -1956,6 +1966,9 @@
 	char *params, *command = NULL, *caller = NULL, *conf = NULL;
 	struct ast_conference *cnf;
 	struct ast_conf_user *user = NULL;
+	struct localuser *u;
+	
+	LOCAL_USER_ADD(u);
 
 	ast_mutex_lock(&conflock);
 	/* The param has the conference number the user and the command to execute */
@@ -1968,6 +1981,7 @@
 		if (!command) {
 			ast_log(LOG_WARNING, "MeetmeAdmin requires a command!\n");
 			ast_mutex_unlock(&conflock);
+			LOCAL_USER_REMOVE(u);
 			return -1;
 		}
 		cnf = confs;
@@ -2059,6 +2073,9 @@
 		}
 	}
 	ast_mutex_unlock(&conflock);
+
+	LOCAL_USER_REMOVE(u);
+	
 	return 0;
 }
 

Index: app_milliwatt.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_milliwatt.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- app_milliwatt.c	18 Oct 2005 22:52:21 -0000	1.13
+++ app_milliwatt.c	19 Oct 2005 18:19:02 -0000	1.14
@@ -127,6 +127,7 @@
 	if (ast_activate_generator(chan,&milliwattgen,"milliwatt") < 0)
 	{
 		ast_log(LOG_WARNING,"Failed to activate generator on '%s'\n",chan->name);
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 	while(!ast_safe_sleep(chan, 10000));

Index: app_mp3.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_mp3.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- app_mp3.c	18 Oct 2005 22:52:21 -0000	1.28
+++ app_mp3.c	19 Oct 2005 18:19:02 -0000	1.29
@@ -127,21 +127,27 @@
 		char offset[AST_FRIENDLY_OFFSET];
 		short frdata[160];
 	} myf;
-	if (!data) {
+	
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "MP3 Playback requires an argument (filename)\n");
 		return -1;
 	}
+
+	LOCAL_USER_ADD(u);
+
 	if (pipe(fds)) {
 		ast_log(LOG_WARNING, "Unable to create pipe\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
-	LOCAL_USER_ADD(u);
+	
 	ast_stopstream(chan);
 
 	owriteformat = chan->writeformat;
 	res = ast_set_write_format(chan, AST_FORMAT_SLINEAR);
 	if (res < 0) {
 		ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 	
@@ -208,11 +214,14 @@
 	}
 	close(fds[0]);
 	close(fds[1]);
-	LOCAL_USER_REMOVE(u);
+	
 	if (pid > -1)
 		kill(pid, SIGKILL);
 	if (!res && owriteformat)
 		ast_set_write_format(chan, owriteformat);
+
+	LOCAL_USER_REMOVE(u);
+	
 	return res;
 }
 

Index: app_muxmon.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_muxmon.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- app_muxmon.c	18 Oct 2005 22:52:21 -0000	1.3
+++ app_muxmon.c	19 Oct 2005 18:19:02 -0000	1.4
@@ -382,34 +382,36 @@
 		*filename = NULL,
 		*post_process = NULL;
 	
-	if (!data) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "muxmon requires an argument\n");
 		return -1;
 	}
 
-	if (!(args = ast_strdupa(data))) {
+	LOCAL_USER_ADD(u);
+
+	args = ast_strdupa(data);	
+	if (!args) {
 		ast_log(LOG_WARNING, "Memory Error!\n");
-        return -1;
+		LOCAL_USER_REMOVE(u);
+		return -1;
 	}
-	
 
 	if ((argc = ast_separate_app_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
 		filename = argv[0];
-		if ( argc > 1) {
+		if (argc > 1) {
 			options = argv[1];
 		}
-		if ( argc > 2) {
+		if (argc > 2) {
 			post_process = argv[2];
 		}
 	}
 	
 	if (!filename || ast_strlen_zero(filename)) {
 		ast_log(LOG_WARNING, "Muxmon requires an argument (filename)\n");
-        return -1;
+		LOCAL_USER_REMOVE(u);
+		return -1;
 	}
 
-	LOCAL_USER_ADD(u);
-
 	if (options) {
 		char *opts[3] = {};
 		ast_parseoptions(muxmon_opts, &flags, opts, options);
@@ -440,13 +442,13 @@
 			else {
 				readvol = writevol = minmax(x, 4);
 				x = get_volfactor(readvol);
-                readvol = minmax(x, 16);
+				readvol = minmax(x, 16);
 				x = get_volfactor(writevol);
-                writevol = minmax(x, 16);
+				writevol = minmax(x, 16);
 			}
 		}
 	}
-		pbx_builtin_setvar_helper(chan, "MUXMON_FILENAME", filename);
+	pbx_builtin_setvar_helper(chan, "MUXMON_FILENAME", filename);
 	launch_monitor_thread(chan, filename, flags.flags, readvol, writevol, post_process);
 
 	LOCAL_USER_REMOVE(u);

Index: app_nbscat.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_nbscat.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- app_nbscat.c	18 Oct 2005 22:52:21 -0000	1.13
+++ app_nbscat.c	19 Oct 2005 18:19:02 -0000	1.14
@@ -117,17 +117,22 @@
 		char offset[AST_FRIENDLY_OFFSET];
 		short frdata[160];
 	} myf;
+	
+	LOCAL_USER_ADD(u);
+
 	if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fds)) {
 		ast_log(LOG_WARNING, "Unable to create socketpair\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
-	LOCAL_USER_ADD(u);
+	
 	ast_stopstream(chan);
 
 	owriteformat = chan->writeformat;
 	res = ast_set_write_format(chan, AST_FORMAT_SLINEAR);
 	if (res < 0) {
 		ast_log(LOG_WARNING, "Unable to set write format to signed linear\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 	
@@ -191,11 +196,14 @@
 	}
 	close(fds[0]);
 	close(fds[1]);
-	LOCAL_USER_REMOVE(u);
+	
 	if (pid > -1)
 		kill(pid, SIGKILL);
 	if (!res && owriteformat)
 		ast_set_write_format(chan, owriteformat);
+
+	LOCAL_USER_REMOVE(u);
+
 	return res;
 }
 

Index: app_osplookup.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_osplookup.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- app_osplookup.c	18 Oct 2005 22:52:21 -0000	1.11
+++ app_osplookup.c	19 Oct 2005 18:19:02 -0000	1.12
@@ -109,10 +109,21 @@
 	char *temp;
 	char *provider, *opts=NULL;
 	struct ast_osp_result result;
-	if (!data || ast_strlen_zero(data) || !(temp = ast_strdupa(data))) {
+	
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "OSPLookup requires an argument (extension)\n");
 		return -1;
 	}
+
+	LOCAL_USER_ADD(u);
+
+	temp = ast_strdupa(data);
+	if (!temp) {
+		ast_log(LOG_ERROR, "Out of memory!\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
+
 	provider = strchr(temp, '|');
 	if (provider) {
 		*provider = '\0';
@@ -123,7 +134,7 @@
 			opts++;
 		}
 	}
-	LOCAL_USER_ADD(u);
+	
 	ast_log(LOG_DEBUG, "Whoo hoo, looking up OSP on '%s' via '%s'\n", temp, provider ? provider : "<default>");
 	if ((res = ast_osp_lookup(chan, provider, temp, chan->cid.cid_num, &result)) > 0) {
 		char tmp[80];
@@ -157,10 +168,14 @@
 	char *temp;
 	int cause;
 	struct ast_osp_result result;
+
 	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "OSPNext should have an argument (cause)\n");
+		return -1;
 	}
+	
 	LOCAL_USER_ADD(u);
+
 	cause = str2cause((char *)data);
 	temp = pbx_builtin_getvar_helper(chan, "OSPHANDLE");
 	result.handle = -1;
@@ -201,9 +216,14 @@
 	int cause;
 	time_t start=0, duration=0;
 	struct ast_osp_result result;
+
 	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "OSPFinish should have an argument (cause)\n");
+		return -1;
 	}
+
+	LOCAL_USER_ADD(u);	
+
 	if (chan->cdr) {
 		start = chan->cdr->answer.tv_sec;
 		if (start)
@@ -212,7 +232,7 @@
 			duration = 0;
 	} else
 		ast_log(LOG_WARNING, "OSPFinish called on channel '%s' with no CDR!\n", chan->name);
-	LOCAL_USER_ADD(u);
+	
 	cause = str2cause((char *)data);
 	temp = pbx_builtin_getvar_helper(chan, "OSPHANDLE");
 	result.handle = -1;

Index: app_page.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_page.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- app_page.c	18 Oct 2005 22:52:21 -0000	1.6
+++ app_page.c	19 Oct 2005 18:19:02 -0000	1.7
@@ -120,25 +120,25 @@
 	char *tmp;
 	int res=0;
 
-	if (!data)
-		return -1;
-
-	if (ast_strlen_zero(data)) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "This application requires at least one argument (destination(s) to page)\n");
 		return -1;
 	}
 
+	LOCAL_USER_ADD(u);
+
 	if (!(app = pbx_findapp("MeetMe"))) {
 		ast_log(LOG_WARNING, "There is no MeetMe application available!\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	};
 
-	if (!(options = ast_strdupa((char *) data))) {
+	options = ast_strdupa(data);
+	if (!options) {
 		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
-		
-	LOCAL_USER_ADD(u);
 
 	tmp = strsep(&options, "|");
 	if (options)

Index: app_parkandannounce.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_parkandannounce.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- app_parkandannounce.c	18 Oct 2005 22:52:21 -0000	1.17
+++ app_parkandannounce.c	19 Oct 2005 18:19:02 -0000	1.18
@@ -80,15 +80,19 @@
 	int outstate;
 
 	struct localuser *u;
-	if(!data || (data && !strlen(data))) {
+
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "ParkAndAnnounce requires arguments: (announce:template|timeout|dial|[return_context])\n");
 		return -1;
 	}
   
+	LOCAL_USER_ADD(u);
+
 	l=strlen(data)+2;
 	orig_s=malloc(l);
 	if(!orig_s) {
 		ast_log(LOG_WARNING, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 	s=orig_s;
@@ -98,6 +102,7 @@
 	if(! template) {
 		ast_log(LOG_WARNING, "PARK: An announce template must be defined\n");
 		free(orig_s);
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
   
@@ -109,6 +114,7 @@
 	if(!dial) {
 		ast_log(LOG_WARNING, "PARK: A dial resource must be specified i.e: Console/dsp or Zap/g1/5551212\n");
 		free(orig_s);
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	} else {
 		dialtech=strsep(&dial, "/");
@@ -141,6 +147,7 @@
 	if(atoi(priority) < 0) {
 		ast_log(LOG_WARNING, "Priority '%s' must be a number > 0\n", priority);
 		free(orig_s);
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 	/* At this point we have a priority and maybe an extension and a context */
@@ -153,7 +160,6 @@
 		chan->priority++;
 	}
 
-
 	if(option_verbose > 2) {
 		ast_verbose( VERBOSE_PREFIX_3 "Return Context: (%s,%s,%d) ID: %s\n", chan->context,chan->exten, chan->priority, chan->cid.cid_num);
 		if(!ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
@@ -161,8 +167,6 @@
 		}
 	}
   
-	LOCAL_USER_ADD(u);
-
 	/* we are using masq_park here to protect * from touching the channel once we park it.  If the channel comes out of timeout
 	before we are done announcing and the channel is messed with, Kablooeee.  So we use Masq to prevent this.  */
 
@@ -228,9 +232,10 @@
 
 	ast_stopstream(dchan);  
 	ast_hangup(dchan);
-
-	LOCAL_USER_REMOVE(u);
 	free(orig_s);
+	
+	LOCAL_USER_REMOVE(u);
+	
 	return res;
 }
 

Index: app_playback.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_playback.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- app_playback.c	18 Oct 2005 22:52:21 -0000	1.21
+++ app_playback.c	19 Oct 2005 18:19:02 -0000	1.22
@@ -69,10 +69,21 @@
 	int option_noanswer = 0;
 	char *stringp = NULL;
 	char *front = NULL, *back = NULL;
-	if (!data || ast_strlen_zero((char *)data) || !(tmp = ast_strdupa(data))) {
+	
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "Playback requires an argument (filename)\n");
 		return -1;
 	}
+
+	LOCAL_USER_ADD(u);
+
+	tmp = ast_strdupa(data);
+	if (!tmp) {
+		ast_log(LOG_ERROR, "Out of memory!\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;	
+	}
+
 	stringp = tmp;
 	strsep(&stringp, "|");
 	options = strsep(&stringp, "|");
@@ -80,7 +91,7 @@
 		option_skip = 1;
 	if (options && !strcasecmp(options, "noanswer"))
 		option_noanswer = 1;
-	LOCAL_USER_ADD(u);
+	
 	if (chan->_state != AST_STATE_UP) {
 		if (option_skip) {
 			/* At the user's option, skip if the line is not up */

Index: app_queue.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_queue.c,v
retrieving revision 1.171
retrieving revision 1.172
diff -u -d -r1.171 -r1.172
--- app_queue.c	18 Oct 2005 22:52:21 -0000	1.171
+++ app_queue.c	19 Oct 2005 18:19:02 -0000	1.172
@@ -2556,25 +2556,27 @@
 	struct localuser *u;
 	char *queuename, *interface;
 
-	if (!data) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "PauseQueueMember requires an argument ([queuename]|interface])\n");
 		return -1;
 	}
 
+	LOCAL_USER_ADD(u);
+
 	queuename = ast_strdupa((char *)data);
 	if (!queuename) {
 		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
 	interface = strchr(queuename, '|');
 	if (!interface) {
 		ast_log(LOG_WARNING, "Missing interface argument to PauseQueueMember ([queuename]|interface])\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
-	LOCAL_USER_ADD(u);
-
 	*interface = '\0';
 	interface++;
 
@@ -2584,6 +2586,7 @@
 			LOCAL_USER_REMOVE(u);
 			return 0;
 		}
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
@@ -2597,25 +2600,27 @@
 	struct localuser *u;
 	char *queuename, *interface;
 
-	if (!data) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "UnpauseQueueMember requires an argument ([queuename]|interface])\n");
 		return -1;
 	}
 
+	LOCAL_USER_ADD(u);
+
 	queuename = ast_strdupa((char *)data);
 	if (!queuename) {
 		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
 	interface = strchr(queuename, '|');
 	if (!interface) {
 		ast_log(LOG_WARNING, "Missing interface argument to PauseQueueMember ([queuename]|interface])\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
-	LOCAL_USER_ADD(u);
-
 	*interface = '\0';
 	interface++;
 
@@ -2625,6 +2630,7 @@
 			LOCAL_USER_REMOVE(u);
 			return 0;
 		}
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
@@ -2641,19 +2647,20 @@
 	char tmpchan[256]="";
 	char *interface = NULL;
 
-	if (!data) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "RemoveQueueMember requires an argument (queuename[|interface])\n");
 		return -1;
 	}
 
-	info = ast_strdupa((char *)data);
+	LOCAL_USER_ADD(u);
+
+	info = ast_strdupa(data);
 	if (!info) {
 		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
-	LOCAL_USER_ADD(u);
-
 	queuename = info;
 	if (queuename) {
 		interface = strchr(queuename, '|');
@@ -2704,17 +2711,19 @@
 	char *penaltys=NULL;
 	int penalty = 0;
 
-	if (!data) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "AddQueueMember requires an argument (queuename[|[interface][|penalty]])\n");
 		return -1;
 	}
 
-	info = ast_strdupa((char *)data);
+	LOCAL_USER_ADD(u);
+
+	info = ast_strdupa(data);
 	if (!info) {
 		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
-	LOCAL_USER_ADD(u);
 
 	queuename = info;
 	if (queuename) {
@@ -2794,7 +2803,7 @@
 		ast_log(LOG_WARNING, "Queue requires an argument: queuename[|options[|URL][|announceoverride][|timeout]]\n");
 		return -1;
 	}
-	
+
 	LOCAL_USER_ADD(u);
 
 	/* Setup our queue entry */
@@ -3024,12 +3033,15 @@
 	struct localuser *u;
 	struct member *m;
 
+	LOCAL_USER_ACF_ADD(u);
+
+	ast_copy_string(buf, "0", len);
+	
 	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_ERROR, "QUEUEAGENTCOUNT requires an argument: queuename\n");
-		return "0";
+		LOCAL_USER_REMOVE(u);
+		return buf;
 	}
-	
-	LOCAL_USER_ACF_ADD(u);
 
 	ast_mutex_lock(&qlock);
 

Index: app_random.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_random.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- app_random.c	18 Oct 2005 22:52:21 -0000	1.9
+++ app_random.c	19 Oct 2005 18:19:02 -0000	1.10
@@ -61,13 +61,20 @@
 	char *s;
 	char *prob;
 	int probint;
-
-	if (!data) {
+	
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "Random requires an argument ([probability]:[[context|]extension|]priority)\n");
 		return -1;
 	}
+	
 	LOCAL_USER_ADD(u);
-	s = ast_strdupa((void *) data);
+
+	s = ast_strdupa(data);
+	if (!s) {
+		ast_log(LOG_ERROR, "Out of memory!\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
 
 	prob = strsep(&s,":");
 	if ((!prob) || (sscanf(prob, "%d", &probint) != 1))

Index: app_read.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_read.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- app_read.c	18 Oct 2005 22:52:21 -0000	1.23
+++ app_read.c	19 Oct 2005 18:19:02 -0000	1.24
@@ -89,11 +89,23 @@
 	char *argcopy = NULL;
 	char *args[8];
 
-	if (data)
-		argcopy = ast_strdupa((char *)data);
+	if (!data || ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "Read requires an argument (variable)\n");
+		return -1;
+	}
+
+	LOCAL_USER_ADD(u);
+	
+	argcopy = ast_strdupa(data);
+	if (!argcopy) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
 
 	if (ast_separate_app_args(argcopy, '|', args, sizeof(args) / sizeof(args[0])) < 1) {
-		ast_log(LOG_WARNING, "Cannot Parse Arguements.\n");
+		ast_log(LOG_WARNING, "Cannot Parse Arguments.\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
@@ -142,9 +154,10 @@
 	}
 	if (!(varname) || ast_strlen_zero(varname)) {
 		ast_log(LOG_WARNING, "Invalid! Usage: Read(variable[|filename][|maxdigits][|option][|attempts][|timeout])\n\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
-	LOCAL_USER_ADD(u);
+	
 	if (chan->_state != AST_STATE_UP) {
 		if (option_skip) {
 			/* At the user's option, skip if the line is not up */

Index: app_readfile.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_readfile.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- app_readfile.c	18 Oct 2005 22:52:21 -0000	1.9
+++ app_readfile.c	19 Oct 2005 18:19:02 -0000	1.10
@@ -63,10 +63,17 @@
 	char *s, *varname=NULL, *file=NULL, *length=NULL, *returnvar=NULL;
 	int len=0;
 
+	if (!data || ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "ReadFile require an argument!\n");
+		return -1;
+	}
+
+	LOCAL_USER_ADD(u);
 
 	s = ast_strdupa(data);
 	if (!s) {
 		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
@@ -76,18 +83,17 @@
 
 	if (!varname || !file) {
 		ast_log(LOG_ERROR, "No file or variable specified!\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
-	LOCAL_USER_ADD(u);
 	if (length) {
 		if ((sscanf(length, "%d", &len) != 1) || (len < 0)) {
 			ast_log(LOG_WARNING, "%s is not a positive number, defaulting length to max\n", length);
 			len = 0;
 		}
 	}
-	
-	
+
 	returnvar = ast_read_textfile(file);
 	if(len > 0){
 		if(len < strlen(returnvar))

Index: app_realtime.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_realtime.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- app_realtime.c	18 Oct 2005 22:52:21 -0000	1.13
+++ app_realtime.c	19 Oct 2005 18:19:02 -0000	1.14
@@ -129,11 +129,14 @@
 	char *family=NULL, *colmatch=NULL, *value=NULL, *newcol=NULL, *newval=NULL;
 	struct localuser *u;
 	int res = 0;
-	if (!data) {
-        ast_log(LOG_ERROR,"Invalid input %s\n",UUSAGE);
-        return -1;
-    }
+
+	if (!data || ast_strlen_zero(data)) {
+		ast_log(LOG_ERROR,"Invalid input: usage %s\n",UUSAGE);
+		return -1;
+	}
+	
 	LOCAL_USER_ADD(u);
+
 	if ((family = ast_strdupa(data))) {
 		if ((colmatch = strchr(family,'|'))) {
 			crop_data(colmatch);
@@ -155,8 +158,8 @@
 	}
 
 	LOCAL_USER_REMOVE(u);
+	
 	return res;
-
 }
 
 
@@ -167,12 +170,14 @@
 	struct ast_variable *var, *itt;
 	char *family=NULL, *colmatch=NULL, *value=NULL, *prefix=NULL, *vname=NULL;
 	size_t len;
-
-	if (!data) {
+		
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_ERROR,"Invalid input: usage %s\n",USAGE);
 		return -1;
 	}
+	
 	LOCAL_USER_ADD(u);
+
 	if ((family = ast_strdupa(data))) {
 		if ((colmatch = strchr(family,'|'))) {
 			crop_data(colmatch);

Index: app_record.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_record.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- app_record.c	18 Oct 2005 22:52:21 -0000	1.38
+++ app_record.c	19 Oct 2005 18:19:02 -0000	1.39
@@ -99,18 +99,23 @@
 	int rfmt = 0;
 	int flags;
 	
-
-
-
 	/* The next few lines of code parse out the filename and header from the input string */
 	if (!data || ast_strlen_zero(data)) { /* no data implies no filename or anything is present */
 		ast_log(LOG_WARNING, "Record requires an argument (filename)\n");
 		return -1;
 	}
+
+	LOCAL_USER_ADD(u);
+
 	/* Yay for strsep being easy */
 	vdata = ast_strdupa(data);
+	if (!vdata) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
+
 	p = vdata;
-	
 	filename = strsep(&p, "|");
 	silstr = strsep(&p, "|");
 	maxstr = strsep(&p, "|");	
@@ -129,6 +134,7 @@
 	}
 	if (!ext) {
 		ast_log(LOG_WARNING, "No extension specified to filename!\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 	if (silstr) {
@@ -180,7 +186,7 @@
 		strncpy(tmp, filename, sizeof(tmp)-1);
 	/* end of routine mentioned */
 	
-	LOCAL_USER_ADD(u);
+	
 	
 	if (chan->_state != AST_STATE_UP) {
 		if (option_skip) {
@@ -213,11 +219,13 @@
 			res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
 			if (res < 0) {
 				ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
+				LOCAL_USER_REMOVE(u);
 				return -1;
 			}
 			sildet = ast_dsp_new();
 			if (!sildet) {
 				ast_log(LOG_WARNING, "Unable to create silence detector :(\n");
+				LOCAL_USER_REMOVE(u);
 				return -1;
 			}
 			ast_dsp_set_threshold(sildet, 256);
@@ -308,7 +316,6 @@
 	} else
 		ast_log(LOG_WARNING, "Could not answer channel '%s'\n", chan->name);
 	
-	LOCAL_USER_REMOVE(u);
 	if ((silence > 0) && rfmt) {
 		res = ast_set_read_format(chan, rfmt);
 		if (res)
@@ -316,6 +323,9 @@
 		if (sildet)
 			ast_dsp_free(sildet);
 	}
+
+	LOCAL_USER_REMOVE(u);
+
 	return res;
 }
 

Index: app_senddtmf.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_senddtmf.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- app_senddtmf.c	18 Oct 2005 22:52:21 -0000	1.12
+++ app_senddtmf.c	19 Oct 2005 18:19:02 -0000	1.13
@@ -62,21 +62,33 @@
 	char *digits = NULL, *to = NULL;
 	int timeout = 250;
 
-	if (data && !ast_strlen_zero(data) && (digits = ast_strdupa((char *)data))) {
-		if((to = strchr(digits,'|'))) {
-			*to = '\0';
-			to++;
-			timeout = atoi(to);
-		}
-		LOCAL_USER_ADD(u);
-		if(timeout <= 0)
-			timeout = 250;
+	if (!data || ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "SendDTMF requires an argument (digits or *#aAbBcCdD)\n");
+		return 0;
+	}
 
-		res = ast_dtmf_stream(chan,NULL,digits,timeout);
+	LOCAL_USER_ADD(u);
+
+	digits = ast_strdupa(data);
+	if (!digits) {
+		ast_log(LOG_ERROR, "Out of Memory!\n");
 		LOCAL_USER_REMOVE(u);
-	} else {
-		ast_log(LOG_WARNING, "SendDTMF requires an argument (digits or *#aAbBcCdD)\n");
+		return -1;
+	}
+
+	if ((to = strchr(digits,'|'))) {
+		*to = '\0';
+		to++;
+		timeout = atoi(to);
 	}
+		
+	if(timeout <= 0)
+		timeout = 250;
+
+	res = ast_dtmf_stream(chan,NULL,digits,timeout);
+		
+	LOCAL_USER_REMOVE(u);
+
 	return res;
 }
 

Index: app_sendtext.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_sendtext.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- app_sendtext.c	18 Oct 2005 22:52:21 -0000	1.10
+++ app_sendtext.c	19 Oct 2005 18:19:02 -0000	1.11
@@ -70,13 +70,14 @@
 	int res = 0;
 	struct localuser *u;
 	char *status = "UNSUPPORTED";
-
-	if (!data || !strlen((char *)data)) {
+		
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "SendText requires an argument (text)\n");
 		return -1;
 	}
-
+	
 	LOCAL_USER_ADD(u);
+
 	ast_mutex_lock(&chan->lock);
 	if (!chan->tech->send_text) {
 		ast_mutex_unlock(&chan->lock);

Index: app_setcallerid.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_setcallerid.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- app_setcallerid.c	18 Oct 2005 22:52:21 -0000	1.11
+++ app_setcallerid.c	19 Oct 2005 18:19:02 -0000	1.12
@@ -68,15 +68,17 @@
 	struct localuser *u;
 	int pres = -1;
 
+	LOCAL_USER_ADD(u);
+	
 	pres = ast_parse_caller_presentation(data);
 
 	if (pres < 0) {
 		ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show application SetCallerPres')\n",
 			(char *) data);
+		LOCAL_USER_REMOVE(u);
 		return 0;
 	}
-
-	LOCAL_USER_ADD(u);
+	
 	chan->cid.cid_pres = pres;
 	LOCAL_USER_REMOVE(u);
 	return 0;
@@ -97,14 +99,27 @@
 static int setcallerid_exec(struct ast_channel *chan, void *data)
 {
 	int res = 0;
-	char tmp[256] = "";
+	char *tmp = NULL;
 	char name[256];
 	char num[256];
 	struct localuser *u;
 	char *opt;
 	int anitoo = 0;
-	if (data)
-		ast_copy_string(tmp, (char *)data, sizeof(tmp));
+
+	if (!data || ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "SetCallerID requires an argument!\n");
+		return 0;
+	}
+	
+	LOCAL_USER_ADD(u);
+	
+	tmp = ast_strdupa(data);
+	if (!tmp) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
+	
 	opt = strchr(tmp, '|');
 	if (opt) {
 		*opt = '\0';
@@ -112,10 +127,12 @@
 		if (*opt == 'a')
 			anitoo = 1;
 	}
-	LOCAL_USER_ADD(u);
+	
 	ast_callerid_split(tmp, name, sizeof(name), num, sizeof(num));
 	ast_set_callerid(chan, num, name, anitoo ? num : NULL);
+
 	LOCAL_USER_REMOVE(u);
+	
 	return res;
 }
 

Index: app_setcdruserfield.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_setcdruserfield.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- app_setcdruserfield.c	18 Oct 2005 22:52:21 -0000	1.10
+++ app_setcdruserfield.c	19 Oct 2005 18:19:02 -0000	1.11
@@ -111,9 +111,9 @@
 	struct localuser *u;
 	int res = 0;
 	
-	LOCAL_USER_ADD(u)
-	if (chan->cdr && data) 
-	{
+	LOCAL_USER_ADD(u);
+
+	if (chan->cdr && data) {
 		ast_cdr_setuserfield(chan, (char*)data);
 	}
 
@@ -127,9 +127,9 @@
 	struct localuser *u;
 	int res = 0;
 	
-	LOCAL_USER_ADD(u)
-	if (chan->cdr && data) 
-	{
+	LOCAL_USER_ADD(u);
+
+	if (chan->cdr && data) {
 		ast_cdr_appenduserfield(chan, (char*)data);
 	}
 

Index: app_setcidname.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_setcidname.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- app_setcidname.c	18 Oct 2005 22:52:21 -0000	1.12
+++ app_setcidname.c	19 Oct 2005 18:19:02 -0000	1.13
@@ -60,8 +60,7 @@
 
 static int setcallerid_exec(struct ast_channel *chan, void *data)
 {
-	int res = 0;
-	char tmp[256] = "";
+	char *tmp = NULL;	
 	struct localuser *u;
 	char *opt;
 	static int deprecation_warning = 0;
@@ -71,16 +70,30 @@
 		deprecation_warning = 1;
 	}
 
-	if (data)
-		ast_copy_string(tmp, (char *)data, sizeof(tmp));
+	if (!data || ast_strlen_zero(data)) {
+		ast_log(LOG_ERROR, "SetCIDName requires an argument!\n");
+		return 0;	
+	}
+
+	LOCAL_USER_ADD(u);
+
+	tmp = ast_strdupa(data);
+	if (!tmp) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
+	
 	opt = strchr(tmp, '|');
 	if (opt) {
 		*opt = '\0';
 	}
-	LOCAL_USER_ADD(u);
+	
 	ast_set_callerid(chan, NULL, tmp, NULL);
+
 	LOCAL_USER_REMOVE(u);
-	return res;
+	
+	return 0;
 }
 
 int unload_module(void)

Index: app_setcidnum.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_setcidnum.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- app_setcidnum.c	18 Oct 2005 22:52:21 -0000	1.13
+++ app_setcidnum.c	19 Oct 2005 18:19:02 -0000	1.14
@@ -65,16 +65,21 @@
 	struct localuser *u;
 	char *opt;
 	int anitoo = 0;
-	char tmp[256];
+	char *tmp = NULL;
 	static int deprecation_warning = 0;
 
+	LOCAL_USER_ADD(u);
+	
 	if (!deprecation_warning) {
 		ast_log(LOG_WARNING, "SetCIDNum is deprecated, please use Set(CALLERID(number)=value) instead.\n");
 		deprecation_warning = 1;
 	}
 
 	if (data)
-		ast_copy_string(tmp, (char *)data, sizeof(tmp));
+		tmp = ast_strdupa(data);
+	else
+		tmp = "";
+	
 	opt = strchr(tmp, '|');
 	if (opt) {
 		*opt = '\0';
@@ -82,9 +87,11 @@
 		if (*opt == 'a')
 			anitoo = 1;
 	}
-	LOCAL_USER_ADD(u);
+	
 	ast_set_callerid(chan, tmp, NULL, anitoo ? tmp : NULL);
+
 	LOCAL_USER_REMOVE(u);
+	
 	return res;
 }
 

Index: app_setrdnis.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_setrdnis.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- app_setrdnis.c	18 Oct 2005 22:52:21 -0000	1.8
+++ app_setrdnis.c	19 Oct 2005 18:19:02 -0000	1.9
@@ -61,22 +61,25 @@
 {
 	struct localuser *u;
 	char *opt, *n, *l;
-	char tmp[256];
+	char *tmp = NULL;
 	static int deprecation_warning = 0;
 
+	LOCAL_USER_ADD(u);
+	
 	if (!deprecation_warning) {
 		ast_log(LOG_WARNING, "SetRDNIS is deprecated, please use Set(CALLERID(rdnis)=value) instead.\n");
 		deprecation_warning = 1;
 	}
 
 	if (data)
-		ast_copy_string(tmp, (char *)data, sizeof(tmp));
+		tmp = ast_strdupa(data);
 	else
-		tmp[0] = '\0';
+		tmp = "";	
+
 	opt = strchr(tmp, '|');
 	if (opt)
 		*opt = '\0';
-	LOCAL_USER_ADD(u);
+	
 	n = l = NULL;
 	ast_callerid_parse(tmp, &n, &l);
 	if (l) {
@@ -87,7 +90,9 @@
 		chan->cid.cid_rdnis = (l[0]) ? strdup(l) : NULL;
 		ast_mutex_unlock(&chan->lock);
 	}
+
 	LOCAL_USER_REMOVE(u);
+	
 	return 0;
 }
 

Index: app_settransfercapability.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_settransfercapability.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- app_settransfercapability.c	18 Oct 2005 22:52:21 -0000	1.8
+++ app_settransfercapability.c	19 Oct 2005 18:19:02 -0000	1.9
@@ -70,18 +70,24 @@
 
 static int settransfercapability_exec(struct ast_channel *chan, void *data)
 {
-	char tmp[256] = "";
+	char *tmp = NULL;
 	struct localuser *u;
 	int x;
 	char *opts;
 	int transfercapability = -1;
 	
+	LOCAL_USER_ADD(u);
+	
 	if (data)
-		ast_copy_string(tmp, (char *)data, sizeof(tmp));
+		tmp = ast_strdupa(data);
+	else
+		tmp = "";
+
 	opts = strchr(tmp, '|');
 	if (opts)
 		*opts = '\0';
-	for (x=0;x<sizeof(transcaps) / sizeof(transcaps[0]);x++) {
+	
+	for (x = 0; x < (sizeof(transcaps) / sizeof(transcaps[0])); x++) {
 		if (!strcasecmp(transcaps[x].name, tmp)) {
 			transfercapability = transcaps[x].val;
 			break;
@@ -89,15 +95,18 @@
 	}
 	if (transfercapability < 0) {
 		ast_log(LOG_WARNING, "'%s' is not a valid transfer capability (see 'show application SetTransferCapability')\n", tmp);
-		return 0;
-	} else {
-		LOCAL_USER_ADD(u);
-		chan->transfercapability = (unsigned short)transfercapability;
 		LOCAL_USER_REMOVE(u);
-		if (option_verbose > 2)
-			ast_verbose(VERBOSE_PREFIX_3 "Setting transfer capability to: 0x%.2x - %s.\n", transfercapability, tmp);			
 		return 0;
 	}
+		
+	chan->transfercapability = (unsigned short)transfercapability;
+	
+	if (option_verbose > 2)
+		ast_verbose(VERBOSE_PREFIX_3 "Setting transfer capability to: 0x%.2x - %s.\n", transfercapability, tmp);			
+	
+	LOCAL_USER_REMOVE(u);
+
+	return 0;
 }
 
 

Index: app_skel.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_skel.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- app_skel.c	18 Oct 2005 22:52:21 -0000	1.14
+++ app_skel.c	19 Oct 2005 18:19:02 -0000	1.15
@@ -72,17 +72,24 @@
 	char *opts[2];
 	char *argv[2];
 
-	if (!(args = ast_strdupa((char *)data))) {
-		ast_log(LOG_ERROR, "Out of memory!\n");
-		return -1;
-	}
-
-	if (!data) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "%s requires an argument (dummy|[options])\n",app);
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
 	LOCAL_USER_ADD(u);
+	
+	/* Do our thing here */
+
+	/* We need to make a copy of the input string if we are going to modify it! */
+	args = ast_strdupa(data);	
+	if (!args) {
+		ast_log(LOG_ERROR, "Out of memory!\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
+	
 	if ((argc = ast_separate_app_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
 		dummy = argv[0];
 		options = argv[1];
@@ -101,8 +108,8 @@
 	if (ast_test_flag(&flags, OPTION_C))
 		ast_log(LOG_NOTICE,"Option C is set with : %s\n", opts[1] ? opts[1] : "<unspecified>");
 
-	/* Do our thing here */
 	LOCAL_USER_REMOVE(u);
+	
 	return res;
 }
 

Index: app_sms.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_sms.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- app_sms.c	18 Oct 2005 22:52:21 -0000	1.28
+++ app_sms.c	19 Oct 2005 18:19:02 -0000	1.29
@@ -1363,10 +1363,14 @@
 	struct localuser *u;
 	struct ast_frame *f;
 	sms_t h = { 0 };
+	
+	LOCAL_USER_ADD(u);
+
 	h.ipc0 = h.ipc1 = 20;		  /* phase for cosine */
 	h.dcs = 0xF1;					 /* default */
 	if (!data) {
 		ast_log (LOG_ERROR, "Requires queue name at least\n");
+		LOCAL_USER_REMOVE(u);
 		return -1;
 	}
 
@@ -1379,11 +1383,13 @@
 			answer = 0;
 		if (!*d || *d == '|') {
 			ast_log (LOG_ERROR, "Requires queue name\n");
+			LOCAL_USER_REMOVE(u);
 			return -1;
 		}
 		for (p = d; *p && *p != '|'; p++);
 		if (p - d >= sizeof (h.queue)) {
 			ast_log (LOG_ERROR, "Queue name too long\n");
+			LOCAL_USER_REMOVE(u);
 			return -1;
 		}
 		strncpy (h.queue, d, p - d);
@@ -1452,6 +1458,7 @@
 			h.rx = 0;				  /* sent message */
 			h.mr = -1;
 			sms_writefile (&h);
+			LOCAL_USER_REMOVE(u);
 			return 0;
 		}
 
@@ -1463,7 +1470,6 @@
 		}
 	}
 
-	LOCAL_USER_ADD (u);
 	if (chan->_state != AST_STATE_UP)
 		ast_answer (chan);
 
@@ -1475,14 +1481,14 @@
 	if (res >= 0)
 		res = ast_set_read_format (chan, AST_FORMAT_SLINEAR);
 	if (res < 0) {
-		LOCAL_USER_REMOVE (u);
 		ast_log (LOG_ERROR, "Unable to set to linear mode, giving up\n");
+		LOCAL_USER_REMOVE (u);
 		return -1;
 	}
 
 	if (ast_activate_generator (chan, &smsgen, &h) < 0) {
-		LOCAL_USER_REMOVE (u);
 		ast_log (LOG_ERROR, "Failed to activate generator on '%s'\n", chan->name);
+		LOCAL_USER_REMOVE (u);
 		return -1;
 	}
 

Index: app_softhangup.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_softhangup.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- app_softhangup.c	18 Oct 2005 22:52:21 -0000	1.10
+++ app_softhangup.c	19 Oct 2005 18:19:02 -0000	1.11
@@ -60,17 +60,18 @@
 	char *options, *cut, *cdata, *match;
 	char name[AST_CHANNEL_NAME] = "";
 	int all = 0;
-
-	if (!data) {
+	
+	if (!data || ast_strlen_zero(data)) {
                 ast_log(LOG_WARNING, "SoftHangup requires an argument (Technology/resource)\n");
 		return 0;
 	}
 	
+	LOCAL_USER_ADD(u);
+
 	cdata = ast_strdupa(data);
 	match = strsep(&cdata, "|");
 	options = strsep(&cdata, "|");
 	all = options && strchr(options,'a');
-	LOCAL_USER_ADD(u);
 	c = ast_channel_walk_locked(NULL);
 	while (c) {
 		strncpy(name, c->name, sizeof(name)-1);
@@ -95,6 +96,7 @@
 		}
 		c = ast_channel_walk_locked(c);
 	}
+	
 	LOCAL_USER_REMOVE(u);
 
 	return 0;

Index: app_sql_postgres.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_sql_postgres.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- app_sql_postgres.c	18 Oct 2005 22:52:21 -0000	1.14
+++ app_sql_postgres.c	19 Oct 2005 18:19:02 -0000	1.15
@@ -44,9 +44,6 @@
 
 #include "libpq-fe.h"
 
-#define EXTRA_LOG 0
-
-
 static char *tdesc = "Simple PostgreSQL Interface";
 
 static char *app = "PGSQL";
@@ -501,23 +498,19 @@
 	ast_log(LOG_WARNING,"Debug : %s\n",(char *)data);
 	return(0);
 }
-		
-	
 
 static int PGSQL_exec(struct ast_channel *chan, void *data)
 {
 	struct localuser *u;
 	int result;
 
-#if EXTRA_LOG
-	printf("PRSQL_exec: data=%s\n",(char*)data);
-#endif
-
-	if (!data) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "APP_PGSQL requires an argument (see manual)\n");
 		return -1;
 	}
+	
 	LOCAL_USER_ADD(u);
+
 	result=0;
 	
 	if (strncasecmp("connect",data,strlen("connect"))==0) {
@@ -540,8 +533,8 @@
 	}
 		
 	LOCAL_USER_REMOVE(u);                                                                                
+	
 	return result;
-
 }
 
 int unload_module(void)

Index: app_striplsd.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_striplsd.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- app_striplsd.c	18 Oct 2005 22:52:21 -0000	1.8
+++ app_striplsd.c	19 Oct 2005 18:19:02 -0000	1.9
@@ -64,6 +64,9 @@
 	int maxbytes = 0;
 	int stripcount = 0;
 	int extlen = strlen(chan->exten);
+	struct localuser *u;
+
+	LOCAL_USER_ADD(u);
 
 	maxbytes = sizeof(newexten) - 1;
 	if (data) {
@@ -71,6 +74,7 @@
 	}
 	if (!stripcount) {
 		ast_log(LOG_DEBUG, "Ignoring, since number of digits to strip is 0\n");
+		LOCAL_USER_REMOVE(u);
 		return 0;
 	}
 	if (extlen > stripcount) {
@@ -80,6 +84,9 @@
 		strncpy(newexten, chan->exten, maxbytes);
 	}
 	strncpy(chan->exten, newexten, sizeof(chan->exten)-1);
+
+	LOCAL_USER_REMOVE(u);
+
 	return 0;
 }
 

Index: app_substring.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_substring.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- app_substring.c	18 Oct 2005 22:52:21 -0000	1.13
+++ app_substring.c	19 Oct 2005 18:19:02 -0000	1.14
@@ -75,6 +75,9 @@
   char newexten[AST_MAX_EXTENSION] = "";
   char *count1, *count2;
   char *first, *second, *stringp;
+  struct localuser *u;
+
+  LOCAL_USER_ADD(u);
 
   stringp=alloca(strlen(data)+1);
   ast_log(LOG_WARNING, "The use of Substring application is deprecated. Please use ${variable:a:b} instead\n");
@@ -87,6 +90,7 @@
     count2=strsep(&stringp,"\0");
     if (!first || !second || !count1 || !count2) {
       ast_log(LOG_DEBUG, "Ignoring, since there is no argument: variable or string or count1 or count2\n");
+      LOCAL_USER_REMOVE(u);
       return 0;
     }
     icount1=atoi(count1);
@@ -118,6 +122,9 @@
   } else {
     ast_log(LOG_DEBUG, "Ignoring, no parameters\n");
   }
+
+  LOCAL_USER_REMOVE(u);
+
   return 0;
 }
 

Index: app_system.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_system.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- app_system.c	18 Oct 2005 22:52:21 -0000	1.19
+++ app_system.c	19 Oct 2005 18:19:02 -0000	1.20
@@ -89,11 +89,13 @@
 {
 	int res=0;
 	struct localuser *u;
-	if (!data) {
+	
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "System requires an argument(command)\n");
 		pbx_builtin_setvar_helper(chan, chanvar, "FAILURE");
 		return failmode;
 	}
+
 	LOCAL_USER_ADD(u);
 
 	/* Do our thing here */
@@ -120,6 +122,7 @@
 	} 
 
 	LOCAL_USER_REMOVE(u);
+
 	return res;
 }
 

Index: app_talkdetect.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_talkdetect.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- app_talkdetect.c	18 Oct 2005 22:52:21 -0000	1.14
+++ app_talkdetect.c	19 Oct 2005 18:19:02 -0000	1.15
@@ -65,7 +65,7 @@
 {
 	int res = 0;
 	struct localuser *u;
-	char tmp[256];
+	char *tmp;
 	char *options;
 	char *stringp;
 	struct ast_frame *fr;
@@ -77,11 +77,21 @@
 	int x;
 	int origrformat=0;
 	struct ast_dsp *dsp;
-	if (!data || ast_strlen_zero((char *)data)) {
+	
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "BackgroundDetect requires an argument (filename)\n");
 		return -1;
 	}
-	ast_copy_string(tmp, (char *)data, sizeof(tmp));
+
+	LOCAL_USER_ADD(u);
+
+	tmp = ast_strdupa(data);
+	if (!tmp) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}	
+
 	stringp=tmp;
 	strsep(&stringp, "|");
 	options = strsep(&stringp, "|");
@@ -101,7 +111,6 @@
 	}
 	ast_log(LOG_DEBUG, "Preparing detect of '%s', sil=%d,min=%d,max=%d\n", 
 						tmp, sil, min, max);
-	LOCAL_USER_ADD(u);
 	if (chan->_state != AST_STATE_UP) {
 		/* Otherwise answer unless we're supposed to send this while on-hook */
 		res = ast_answer(chan);

Index: app_test.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_test.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- app_test.c	18 Oct 2005 22:52:21 -0000	1.13
+++ app_test.c	19 Oct 2005 18:19:02 -0000	1.14
@@ -43,6 +43,10 @@
 #include "asterisk/pbx.h"
 #include "asterisk/utils.h"
 
+STANDARD_LOCAL_USER;
+
+LOCAL_USER_DECL;
+
 static char *tdesc = "Interface Test Application";
 
 static char *tests_descrip = 
@@ -123,10 +127,6 @@
 	return res;	
 }
 
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
 static int testclient_exec(struct ast_channel *chan, void *data)
 {
 	struct localuser *u;
@@ -135,7 +135,6 @@
 	char fn[80];
 	char serverver[80];
 	FILE *f;
-	LOCAL_USER_ADD(u);
 	
 	/* Check for test id */
 	if (!testid || ast_strlen_zero(testid)) {
@@ -143,6 +142,8 @@
 		return -1;
 	}
 	
+	LOCAL_USER_ADD(u);
+
 	if (chan->_state != AST_STATE_UP)
 		res = ast_answer(chan);
 	

Index: app_transfer.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_transfer.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- app_transfer.c	18 Oct 2005 22:52:21 -0000	1.15
+++ app_transfer.c	19 Oct 2005 18:19:02 -0000	1.16
@@ -38,6 +38,10 @@
 #include "asterisk/module.h"
 #include "asterisk/options.h"
 
+STANDARD_LOCAL_USER;
+
+LOCAL_USER_DECL;
+
 static const char *tdesc = "Transfer";
 
 static const char *app = "Transfer";
@@ -61,10 +65,6 @@
 "successful and there exists a priority n + 101,\n"
 "then that priority will be taken next.\n" ;
 
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
 static int transfer_exec(struct ast_channel *chan, void *data)
 {
 	int res;
@@ -81,12 +81,15 @@
 		return 0;
 	}
 
+	LOCAL_USER_ADD(u);
+
 	if ((slash = strchr(dest, '/')) && (len = (slash - dest))) {
 		tech = dest;
 		dest = slash + 1;
 		/* Allow execution only if the Tech/destination agrees with the type of the channel */
 		if (strncasecmp(chan->type, tech, len)) {
 			pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "FAILURE");
+			LOCAL_USER_REMOVE(u);
 			return 0;
 		}
 	}
@@ -94,11 +97,10 @@
 	/* Check if the channel supports transfer before we try it */
 	if (!chan->tech->transfer) {
 		pbx_builtin_setvar_helper(chan, "TRANSFERSTATUS", "UNSUPPORTED");
+		LOCAL_USER_REMOVE(u);
 		return 0;
 	}
 
-	LOCAL_USER_ADD(u);
-
 	res = ast_transfer(chan, dest);
 
 	if (res < 0) {

Index: app_txtcidname.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_txtcidname.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- app_txtcidname.c	18 Oct 2005 22:52:21 -0000	1.19
+++ app_txtcidname.c	19 Oct 2005 18:19:02 -0000	1.20
@@ -40,6 +40,10 @@
 #include "asterisk/enum.h"
 #include "asterisk/utils.h"
 
+STANDARD_LOCAL_USER;
+
+LOCAL_USER_DECL;
+
 static char *tdesc = "TXTCIDName";
 
 static char *app = "TXTCIDName";
@@ -51,10 +55,6 @@
 "the variable 'TXTCIDNAME'. TXTCIDName will either be blank\n"
 "or return the value found in the TXT record in DNS.\n" ;
 
-STANDARD_LOCAL_USER;
-
-LOCAL_USER_DECL;
-
 static int txtcidname_exec(struct ast_channel *chan, void *data)
 {
 	int res=0;
@@ -64,6 +64,8 @@
 	struct localuser *u;
 	static int dep_warning = 0;
 
+	LOCAL_USER_ADD(u);
+	
 	if (!dep_warning) {
 		ast_log(LOG_WARNING, "The TXTCIDName application has been deprecated in favor of the TXTCIDNAME dialplan function.\n");
 		dep_warning = 1;
@@ -73,11 +75,11 @@
 		ast_log(LOG_WARNING, "TXTCIDName requires an argument (extension)\n");
 		res = 1;
 	}
-	LOCAL_USER_ADD(u);
+	
 	if (!res) {
 		res = ast_get_txt(chan, data, dest, sizeof(dest), tech, sizeof(tech), txt, sizeof(txt));
 	}
-	LOCAL_USER_REMOVE(u);
+	
 	/* Parse it out */
 	if (res > 0) {
 		if (!ast_strlen_zero(txt)) {
@@ -91,6 +93,9 @@
 		ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
 	} else if (res > 0)
 		res = 0;
+
+	LOCAL_USER_REMOVE(u);
+
 	return res;
 }
 

Index: app_url.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_url.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- app_url.c	18 Oct 2005 22:52:21 -0000	1.12
+++ app_url.c	19 Oct 2005 18:19:02 -0000	1.13
@@ -74,20 +74,29 @@
 {
 	int res = 0;
 	struct localuser *u;
-	char tmp[256];
+	char *tmp;
 	char *options;
 	int local_option_wait=0;
 	int local_option_jump = 0;
 	struct ast_frame *f;
 	char *stringp=NULL;
 	char *status = "FAILURE";
-
-	if (!data || !strlen((char *)data)) {
+	
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "SendURL requires an argument (URL)\n");
 		pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", status);
 		return -1;
 	}
-	strncpy(tmp, (char *)data, sizeof(tmp)-1);
+
+	LOCAL_USER_ADD(u);
+
+	tmp = ast_strdupa(data);
+	if (!tmp) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
+
 	stringp=tmp;
 	strsep(&stringp, "|");
 	options = strsep(&stringp, "|");
@@ -95,7 +104,7 @@
 		local_option_wait = 1;
 	if (options && !strcasecmp(options, "j"))
 		local_option_jump = 1;
-	LOCAL_USER_ADD(u);
+	
 	if (!ast_channel_supports_html(chan)) {
 		/* Does not support transport */
 		if (local_option_jump || option_priority_jumping)

Index: app_userevent.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_userevent.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- app_userevent.c	18 Oct 2005 22:52:21 -0000	1.8
+++ app_userevent.c	19 Oct 2005 18:19:02 -0000	1.9
@@ -62,24 +62,31 @@
 static int userevent_exec(struct ast_channel *chan, void *data)
 {
 	struct localuser *u;
-	char info[512];
-    char eventname[512];
+	char *info;
+	char eventname[512];
 	char *eventbody;
 
-	if (!data || !strlen(data)) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "UserEvent requires an argument (eventname|optional event body)\n");
 		return -1;
 	}
 
-	strncpy(info, (char *)data, strlen((char *)data) + AST_MAX_EXTENSION-1);
+	LOCAL_USER_ADD(u);
+
+	info = ast_strdupa(data);
+	if (!info) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
+
 	snprintf(eventname, sizeof(eventname), "UserEvent%s", info);
 	eventbody = strchr(eventname, '|');
 	if (eventbody) {
 		*eventbody = '\0';
 		eventbody++;
 	}
-	LOCAL_USER_ADD(u);
-
+	
 	if(eventbody) {
             ast_log(LOG_DEBUG, "Sending user event: %s, %s\n", eventname, eventbody);
             manager_event(EVENT_FLAG_USER, eventname, 

Index: app_verbose.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_verbose.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- app_verbose.c	18 Oct 2005 22:52:21 -0000	1.7
+++ app_verbose.c	19 Oct 2005 18:19:02 -0000	1.8
@@ -56,6 +56,9 @@
 {
 	char *vtext;
 	int vsize;
+	struct localuser *u;
+
+	LOCAL_USER_ADD(u);
 
 	if (data) {
 		vtext = ast_strdupa((char *)data);
@@ -93,6 +96,8 @@
 		}
 	}
 
+	LOCAL_USER_REMOVE(u);
+
 	return 0;
 }
 

Index: app_voicemail.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_voicemail.c,v
retrieving revision 1.252
retrieving revision 1.253
diff -u -d -r1.252 -r1.253
--- app_voicemail.c	18 Oct 2005 22:52:21 -0000	1.252
+++ app_voicemail.c	19 Oct 2005 18:19:02 -0000	1.253
@@ -5478,9 +5478,9 @@
 	struct ast_flags flags = { 0 };
 	char *opts[OPT_ARG_ARRAY_SIZE];
 	
-	memset(&leave_options, 0, sizeof(leave_options));
-
 	LOCAL_USER_ADD(u);
+	
+	memset(&leave_options, 0, sizeof(leave_options));
 
 	if (chan->_state != AST_STATE_UP)
 		ast_answer(chan);
@@ -5523,16 +5523,18 @@
 		}
 	} else {
 		res = ast_app_getdata(chan, "vm-whichbox", tmp, sizeof(tmp) - 1, 0);
-		if (res < 0)
+		if (res < 0) {
+			LOCAL_USER_REMOVE(u);
 			return res;
-		if (ast_strlen_zero(tmp))
+		}
+		if (ast_strlen_zero(tmp)) {
+			LOCAL_USER_REMOVE(u);
 			return 0;
+		}	
 	}
 
 	res = leave_voicemail(chan, argv[0], &leave_options);
 
-	LOCAL_USER_REMOVE(u);
-	
 	if (res == ERROR_LOCK_PATH) {
 		ast_log(LOG_ERROR, "Could not leave voicemail. The path is already locked.\n");
 		/*Send the call to n+101 priority, where n is the current priority*/
@@ -5541,6 +5543,8 @@
 		res = 0;
 	}
 	
+	LOCAL_USER_REMOVE(u);
+
 	return res;
 }
 
@@ -5589,13 +5593,20 @@
 	struct ast_vm_user svm;
 	char *context, *box;
 
-	if (!data || !(box = ast_strdupa(data))) {
+	if (!data || ast_strlen_zero(data)) {
 		ast_log(LOG_ERROR, "MailboxExists requires an argument: (vmbox[@context])\n");
 		return -1;
 	}
 
 	LOCAL_USER_ADD(u);
 
+	box = ast_strdupa(data);
+	if (!box) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
+
 	if ((context = strchr(box, '@'))) {
 		*context = '\0';
 		context++;
@@ -5618,6 +5629,8 @@
 	int silent = 0;
 	int res = -1;
 
+	LOCAL_USER_ADD(u);
+	
 	if (s) {
 		s = ast_strdupa(s);
 		if (!s) {
@@ -5637,8 +5650,6 @@
 		silent = (strchr(options, 's')) != NULL;
 	}
 
-	LOCAL_USER_ADD(u);
-
 	if (!vm_authenticate(chan, mailbox, sizeof(mailbox), &vmus, context, NULL, 0, 3, silent)) {
 		pbx_builtin_setvar_helper(chan, "AUTH_MAILBOX", mailbox);
 		pbx_builtin_setvar_helper(chan, "AUTH_CONTEXT", vmus.context);

Index: app_waitforring.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_waitforring.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- app_waitforring.c	18 Oct 2005 22:52:21 -0000	1.8
+++ app_waitforring.c	19 Oct 2005 18:19:02 -0000	1.9
@@ -61,12 +61,15 @@
 	struct ast_frame *f;
 	int res = 0;
 	int ms;
+
 	if (!data || (sscanf(data, "%d", &ms) != 1)) {
                 ast_log(LOG_WARNING, "WaitForRing requires an argument (minimum seconds)\n");
 		return 0;
 	}
-	ms *= 1000;
+
 	LOCAL_USER_ADD(u);
+
+	ms *= 1000;
 	while(ms > 0) {
 		ms = ast_waitfor(chan, ms);
 		if (ms < 0) {

Index: app_waitforsilence.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_waitforsilence.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- app_waitforsilence.c	18 Oct 2005 22:52:21 -0000	1.10
+++ app_waitforsilence.c	19 Oct 2005 18:19:02 -0000	1.11
@@ -152,6 +152,8 @@
 	int maxsilence = 1000;
 	int iterations = 1, i;
 
+	LOCAL_USER_ADD(u);
+	
 	res = ast_answer(chan); /* Answer the channel */
 
 	if (!data || ((sscanf(data, "%d|%d", &maxsilence, &iterations) != 2) &&
@@ -161,7 +163,7 @@
 
 	if (option_verbose > 2)
 		ast_verbose(VERBOSE_PREFIX_3 "Waiting %d time(s) for %d ms silence\n", iterations, maxsilence);
-	LOCAL_USER_ADD(u);
+	
 	res = 1;
 	for (i=0; (i<iterations) && (res == 1); i++) {
 		res = do_waiting(chan, maxsilence);

Index: app_while.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_while.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- app_while.c	18 Oct 2005 22:52:21 -0000	1.11
+++ app_while.c	19 Oct 2005 18:19:02 -0000	1.12
@@ -84,7 +84,14 @@
 	struct ast_app *app = NULL;
 
 	LOCAL_USER_ADD(u);
-	expr = ast_strdupa((char *) data);
+
+	expr = ast_strdupa(data);
+	if (!expr) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
+
 	if ((myapp = strchr(expr,'|'))) {
 		*myapp = '\0';
 		myapp++;

Index: app_zapateller.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_zapateller.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- app_zapateller.c	18 Oct 2005 22:52:21 -0000	1.11
+++ app_zapateller.c	19 Oct 2005 18:19:02 -0000	1.12
@@ -68,7 +68,7 @@
 
 	stringp=data;
         c = strsep(&stringp, "|");
-        while(c && strlen(c)) {
+        while(c && !ast_strlen_zero(c)) {
 		if (!strcasecmp(c, "answer"))
 			answer = 1;
 		else if (!strcasecmp(c, "nocallerid"))

Index: app_zapbarge.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_zapbarge.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- app_zapbarge.c	18 Oct 2005 22:52:21 -0000	1.11
+++ app_zapbarge.c	19 Oct 2005 18:19:02 -0000	1.12
@@ -267,14 +267,17 @@
 	int confno = 0;
 	char confstr[80] = "";
 
+	LOCAL_USER_ADD(u);
+	
 	if (data && !ast_strlen_zero(data)) {
 		if ((sscanf(data, "Zap/%d", &confno) != 1) &&
 		    (sscanf(data, "%d", &confno) != 1)) {
 			ast_log(LOG_WARNING, "ZapBarge Argument (if specified) must be a channel number, not '%s'\n", (char *)data);
+			LOCAL_USER_REMOVE(u);
 			return 0;
 		}
 	}
-	LOCAL_USER_ADD(u);
+	
 	if (chan->_state != AST_STATE_UP)
 		ast_answer(chan);
 

Index: app_zapras.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_zapras.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- app_zapras.c	18 Oct 2005 22:52:21 -0000	1.14
+++ app_zapras.c	19 Oct 2005 18:19:02 -0000	1.15
@@ -197,14 +197,22 @@
 static int zapras_exec(struct ast_channel *chan, void *data)
 {
 	int res=-1;
-	char args[256];
+	char *args;
 	struct localuser *u;
 	ZT_PARAMS ztp;
 
 	if (!data) 
 		data = "";
+
 	LOCAL_USER_ADD(u);
-	ast_copy_string(args, data, sizeof(args));
+
+	args = ast_strdupa(data);
+	if (!args) {
+		ast_log(LOG_ERROR, "Out of memory\n");
+		LOCAL_USER_REMOVE(u);
+		return -1;
+	}
+	
 	/* Answer the channel if it's not up */
 	if (chan->_state != AST_STATE_UP)
 		ast_answer(chan);




More information about the svn-commits mailing list