[Asterisk-code-review] various files - fix some alerts raised by lgtm code analysis (...asterisk[13])

Kevin Harwell asteriskteam at digium.com
Wed Oct 23 16:41:05 CDT 2019


Kevin Harwell has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/13102


Change subject: various files - fix some alerts raised by lgtm code analysis
......................................................................

various files - fix some alerts raised by lgtm code analysis

This patch fixes several issues reported by the lgtm code analysis tool:

https://lgtm.com/projects/g/asterisk/asterisk

Not all reported issues were addressed in this patch. This patch mostly fixes
confirmed reported errors, potential problematic code points, and a few other
"low hanging" warnings or recommendations found in core supported modules.
These include, but are not limited to the following:

* innapropriate stack allocation in loops
* buffer overflows
* variable declaration "hiding" another variable declaration
* comparisons results that are always the same
* ambiguously signed bit-field members
* missing header guards

Change-Id: Id4a881686605d26c94ab5409bc70fcc21efacc25
---
M apps/app_cdr.c
M apps/app_dictate.c
M apps/app_followme.c
M apps/app_minivm.c
M apps/app_playback.c
M apps/app_readexten.c
M apps/app_voicemail.c
M channels/chan_dahdi.c
M channels/chan_dahdi.h
M channels/chan_motif.c
M codecs/ex_alaw.h
M codecs/ex_g722.h
M codecs/ex_ulaw.h
M formats/format_g726.c
M formats/msgsm.h
M include/asterisk/ari.h
M include/asterisk/calendar.h
M include/asterisk/channel_internal.h
M include/asterisk/config_options.h
M include/asterisk/max_forwards.h
M include/asterisk/mixmonitor.h
M include/asterisk/parking.h
M include/asterisk/res_pjsip_presence_xml.h
M include/asterisk/slin.h
M main/app.c
M main/asterisk.c
M main/event.c
M main/file.c
M main/indications.c
M main/manager.c
M main/pbx_variables.c
M main/stasis.c
M main/stasis_cache.c
M res/ari/config.c
M res/parking/parking_bridge_features.c
M res/parking/res_parking.h
M res/res_config_curl.c
M res/res_phoneprov.c
M res/res_pjsip/config_system.c
M res/res_pjsip/config_transport.c
M res/res_pjsip_endpoint_identifier_ip.c
M res/res_pjsip_registrar.c
M res/res_rtp_asterisk.c
M res/stasis/command.c
M res/stasis/control.c
45 files changed, 305 insertions(+), 194 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/02/13102/1

diff --git a/apps/app_cdr.c b/apps/app_cdr.c
index 93510f8..b3b98a3 100644
--- a/apps/app_cdr.c
+++ b/apps/app_cdr.c
@@ -121,13 +121,13 @@
 	/*! The name of the channel to be manipulated */
 	const char *channel_name;
 	/*! Disable the CDR for this channel */
-	int disable:1;
+	unsigned int disable:1;
 	/*! Re-enable the CDR for this channel */
-	int reenable:1;
+	unsigned int reenable:1;
 	/*! Reset the CDR */
-	int reset:1;
+	unsigned int reset:1;
 	/*! If reseting the CDR, keep the variables */
-	int keep_variables:1;
+	unsigned int keep_variables:1;
 };
 
 static void appcdr_callback(void *data, struct stasis_subscription *sub, struct stasis_message *message)
diff --git a/apps/app_dictate.c b/apps/app_dictate.c
index f79ba82..1569a4b 100644
--- a/apps/app_dictate.c
+++ b/apps/app_dictate.c
@@ -151,7 +151,8 @@
 		ast_mkdir(base, 0755);
 		len = strlen(base) + strlen(filein) + 2;
 		if (!path || len > maxlen) {
-			path = ast_alloca(len);
+			ast_free(path);
+			path = ast_malloc(len);
 			memset(path, 0, len);
 			maxlen = len;
 		} else {
@@ -336,6 +337,7 @@
 			ast_frfree(f);
 		}
 	}
+	ast_free(path);
 	if (oldr) {
 		ast_set_read_format(chan, oldr);
 		ao2_ref(oldr, -1);
diff --git a/apps/app_followme.c b/apps/app_followme.c
index dfba0e0..21b9a19 100644
--- a/apps/app_followme.c
+++ b/apps/app_followme.c
@@ -402,7 +402,6 @@
 	char *cat = NULL, *tmp;
 	struct ast_variable *var;
 	struct number *cur, *nm;
-	char *numberstr;
 	int timeout;
 	int numorder;
 	const char *takecallstr;
@@ -523,9 +522,12 @@
 		while (var) {
 			if (!strcasecmp(var->name, "number")) {
 				int idx = 0;
+				char copy[strlen(var->value) + 1];
+				char *numberstr;
 
 				/* Add a new number */
-				numberstr = ast_strdupa(var->value);
+				strcpy(copy, var->value); /* safe */
+				numberstr = copy;
 				if ((tmp = strchr(numberstr, ','))) {
 					*tmp++ = '\0';
 					timeout = atoi(tmp);
@@ -745,10 +747,6 @@
 		}
 
 		tmpto = to;
-		if (to < 0) {
-			to = 1000;
-			tmpto = 1000;
-		}
 		towas = to;
 		winner = ast_waitfor_n(watchers, pos, &to);
 		tmpto -= to;
diff --git a/apps/app_minivm.c b/apps/app_minivm.c
index dae033f..36a5fcf 100644
--- a/apps/app_minivm.c
+++ b/apps/app_minivm.c
@@ -2654,9 +2654,10 @@
 			ast_copy_string(vmu->fullname, var->value, sizeof(vmu->fullname));
 		} else if (!strcasecmp(var->name, "setvar")) {
 			char *varval;
-			char *varname = ast_strdupa(var->value);
+			char varname[strlen(var->value) + 1];
 			struct ast_variable *tmpvar;
 
+			strcpy(varname, var->value); /* safe */
 			if ((varval = strchr(varname, '='))) {
 				*varval = '\0';
 				varval++;
diff --git a/apps/app_playback.c b/apps/app_playback.c
index 65a75ac..b8e3e2f 100644
--- a/apps/app_playback.c
+++ b/apps/app_playback.c
@@ -175,7 +175,7 @@
 static int do_say(say_args_t *a, const char *s, const char *options, int depth)
 {
 	struct ast_variable *v;
-	char *lang, *x, *rule = NULL;
+	char *lang, *x, *rule = NULL, *rule_head = NULL;
 	int ret = 0;
 	struct varshead head = { .first = NULL, .last = NULL };
 	struct ast_var_t *n;
@@ -197,7 +197,7 @@
 	for (;;) {
 		for (v = ast_variable_browse(say_cfg, lang); v ; v = v->next) {
 			if (ast_extension_match(v->name, s)) {
-				rule = ast_strdupa(v->value);
+				rule_head = rule = ast_strdup(v->value);
 				break;
 			}
 		}
@@ -222,6 +222,7 @@
 	n = ast_var_assign("SAY", s);
 	if (!n) {
 		ast_log(LOG_ERROR, "Memory allocation error in do_say\n");
+		ast_free(rule_head);
 		return -1;
 	}
 	AST_LIST_INSERT_HEAD(&head, n, entries);
@@ -283,6 +284,7 @@
 		}
 	}
 	ast_var_delete(n);
+	ast_free(rule_head);
 	return ret;
 }
 
diff --git a/apps/app_readexten.c b/apps/app_readexten.c
index a809f92..20dc8eb 100644
--- a/apps/app_readexten.c
+++ b/apps/app_readexten.c
@@ -172,8 +172,7 @@
 	if (timeout <= 0)
 		timeout = ast_channel_pbx(chan) ? ast_channel_pbx(chan)->rtimeoutms : 10000;
 
-	if (digit_timeout <= 0)
-		digit_timeout = ast_channel_pbx(chan) ? ast_channel_pbx(chan)->dtimeoutms : 5000;
+	digit_timeout = ast_channel_pbx(chan) ? ast_channel_pbx(chan)->dtimeoutms : 5000;
 
 	if (ast_test_flag(&flags, OPT_INDICATION) && !ast_strlen_zero(arglist.filename)) {
 		ts = ast_get_indication_tone(ast_channel_zone(chan), arglist.filename);
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index fa5aa5a..292ebec 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -1848,7 +1848,7 @@
 	struct ast_config   *cfg = NULL;
 	struct ast_variable *var = NULL;
 	struct ast_category *cat = NULL;
-	char *category = NULL, *value = NULL, *new = NULL;
+	char *category = NULL;
 	const char *tmp = NULL;
 	struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS };
 	char secretfn[PATH_MAX] = "";
@@ -1875,24 +1875,27 @@
 		if ((cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags)) && valid_config(cfg)) {
 			while ((category = ast_category_browse(cfg, category))) {
 				if (!strcasecmp(category, vmu->context)) {
+					char *value = NULL, *new = NULL;
 					if (!(tmp = ast_variable_retrieve(cfg, category, vmu->mailbox))) {
 						ast_log(AST_LOG_WARNING, "We could not find the mailbox.\n");
 						break;
 					}
 					value = strstr(tmp, ",");
 					if (!value) {
-						new = ast_alloca(strlen(newpassword)+1);
+						new = ast_malloc(strlen(newpassword)+1);
 						sprintf(new, "%s", newpassword);
 					} else {
-						new = ast_alloca((strlen(value) + strlen(newpassword) + 1));
+						new = ast_malloc((strlen(value) + strlen(newpassword) + 1));
 						sprintf(new, "%s%s", newpassword, value);
 					}
 					if (!(cat = ast_category_get(cfg, category, NULL))) {
 						ast_log(AST_LOG_WARNING, "Failed to get category structure.\n");
+						ast_free(new);
 						break;
 					}
 					ast_variable_update(cat, vmu->mailbox, new, NULL, 0);
 					found = 1;
+					ast_free(new);
 				}
 			}
 			/* save the results */
@@ -1916,13 +1919,14 @@
 			for (category = ast_category_browse(cfg, NULL); category; category = ast_category_browse(cfg, category)) {
 				ast_debug(4, "users.conf: %s\n", category);
 				if (!strcasecmp(category, vmu->mailbox)) {
+					char new[strlen(newpassword) + 1];
 					if (!ast_variable_retrieve(cfg, category, "vmsecret")) {
 						ast_debug(3, "looks like we need to make vmsecret!\n");
 						var = ast_variable_new("vmsecret", newpassword, "");
 					} else {
 						var = NULL;
 					}
-					new = ast_alloca(strlen(newpassword) + 1);
+
 					sprintf(new, "%s", newpassword);
 					if (!(cat = ast_category_get(cfg, category, NULL))) {
 						ast_debug(4, "failed to get category!\n");
@@ -2245,7 +2249,6 @@
 	struct vm_state *vms_p;
 	char *file, *filename;
 	char dest[PATH_MAX];
-	char *attachment;
 	int i;
 	BODY *body;
 	int ret = 0;
@@ -2298,21 +2301,26 @@
 		mail_fetchstructure(vms_p->mailstream, i + 1, &body);
 		/* We have the body, now we extract the file name of the first attachment. */
 		if (body->nested.part && body->nested.part->next && body->nested.part->next->body.parameter->value) {
-			attachment = ast_strdupa(body->nested.part->next->body.parameter->value);
+			char *attachment = body->nested.part->next->body.parameter->value;
+			char copy[strlen(attachment) + 1];
+
+			strcpy(copy, attachment); /* safe */
+			attachment = copy;
+
+			filename = strsep(&attachment, ".");
+			if (!strcmp(filename, file)) {
+				ast_copy_string(vms_p->fn, dir, sizeof(vms_p->fn));
+				vms_p->msgArray[vms_p->curmsg] = i + 1;
+				create_dirpath(dest, sizeof(dest), vmu->context, vms_p->username, "");
+				save_body(body, vms_p, "2", attachment, 0);
+				ret = 0;
+				break;
+			}
 		} else {
 			ast_log(AST_LOG_ERROR, "There is no file attached to this IMAP message.\n");
 			ret = -1;
 			break;
 		}
-		filename = strsep(&attachment, ".");
-		if (!strcmp(filename, file)) {
-			ast_copy_string(vms_p->fn, dir, sizeof(vms_p->fn));
-			vms_p->msgArray[vms_p->curmsg] = i + 1;
-			create_dirpath(dest, sizeof(dest), vmu->context, vms_p->username, "");
-			save_body(body, vms_p, "2", attachment, 0);
-			ret = 0;
-			break;
-		}
 	}
 
 	if (curr_mbox != -1) {
@@ -8174,10 +8182,12 @@
 
 		aliases = ao2_find(mailbox_alias_mappings, box, OBJ_SEARCH_KEY | OBJ_MULTIPLE);
 		while ((mapping = ao2_iterator_next(aliases))) {
+			char alias[strlen(mapping->alias) + 1];
+			strcpy(alias, mapping->alias); /* safe */
 			mailbox = NULL;
 			context = NULL;
 			ast_debug(3, "Found alias mapping: %s -> %s\n", mapping->alias, box);
-			separate_mailbox(ast_strdupa(mapping->alias), &mailbox, &context);
+			separate_mailbox(alias, &mailbox, &context);
 			ast_publish_mwi_state_channel(mailbox, context, new + urgent, old, channel_id);
 			ao2_ref(mapping, -1);
 		}
@@ -8397,12 +8407,12 @@
 			directory_app = pbx_findapp("Directory");
 			if (directory_app) {
 				char vmcontext[256];
-				char *old_context;
-				char *old_exten;
+				char old_context[strlen(ast_channel_context(chan)) + 1];
+				char old_exten[strlen(ast_channel_exten(chan)) + 1];
 				int old_priority;
 				/* make backup copies */
-				old_context = ast_strdupa(ast_channel_context(chan));
-				old_exten = ast_strdupa(ast_channel_exten(chan));
+				strcpy(old_context, ast_channel_context(chan)); /* safe */
+				strcpy(old_exten, ast_channel_exten(chan)); /* safe */
 				old_priority = ast_channel_priority(chan);
 
 				/* call the Directory, changes the channel */
@@ -9075,7 +9085,6 @@
 static int imap_delete_old_greeting (char *dir, struct vm_state *vms)
 {
 	char *file, *filename;
-	char *attachment;
 	char arg[11];
 	int i;
 	BODY* body;
@@ -9104,17 +9113,22 @@
 		mail_fetchstructure(vms->mailstream, i + 1, &body);
 		/* We have the body, now we extract the file name of the first attachment. */
 		if (body->nested.part->next && body->nested.part->next->body.parameter->value) {
-			attachment = ast_strdupa(body->nested.part->next->body.parameter->value);
+			char *attachment = body->nested.part->next->body.parameter->value;
+			char copy[strlen(attachment) + 1];
+
+			strcpy(copy, attachment); /* safe */
+			attachment = copy;
+
+			filename = strsep(&attachment, ".");
+			if (!strcmp(filename, file)) {
+				snprintf(arg, sizeof(arg), "%d", i + 1);
+				mail_setflag(vms->mailstream, arg, "\\DELETED");
+			}
 		} else {
 			ast_log(AST_LOG_ERROR, "There is no file attached to this IMAP message.\n");
 			ast_mutex_unlock(&vms->lock);
 			return -1;
 		}
-		filename = strsep(&attachment, ".");
-		if (!strcmp(filename, file)) {
-			snprintf(arg, sizeof(arg), "%d", i + 1);
-			mail_setflag(vms->mailstream, arg, "\\DELETED");
-		}
 	}
 	mail_expunge(vms->mailstream);
 
@@ -13820,26 +13834,30 @@
 
 	var = ast_variable_browse(cfg, "zonemessages");
 	while (var) {
-		struct vm_zone *z;
-		char *msg_format, *tzone;
+		if (var->value) {
+			struct vm_zone *z;
+			char *msg_format, *tzone;
+			char storage[strlen(var->value) + 1];
 
-		z = ast_malloc(sizeof(*z));
-		if (!z) {
-			return;
-		}
+			z = ast_malloc(sizeof(*z));
+			if (!z) {
+				return;
+			}
 
-		msg_format = ast_strdupa(var->value);
-		tzone = strsep(&msg_format, "|,");
-		if (msg_format) {
-			ast_copy_string(z->name, var->name, sizeof(z->name));
-			ast_copy_string(z->timezone, tzone, sizeof(z->timezone));
-			ast_copy_string(z->msg_format, msg_format, sizeof(z->msg_format));
-			AST_LIST_LOCK(&zones);
-			AST_LIST_INSERT_HEAD(&zones, z, list);
-			AST_LIST_UNLOCK(&zones);
-		} else {
-			ast_log(AST_LOG_WARNING, "Invalid timezone definition at line %d\n", var->lineno);
-			ast_free(z);
+			strcpy(storage, var->value); /* safe */
+			msg_format = storage;
+			tzone = strsep(&msg_format, "|,");
+			if (msg_format) {
+				ast_copy_string(z->name, var->name, sizeof(z->name));
+				ast_copy_string(z->timezone, tzone, sizeof(z->timezone));
+				ast_copy_string(z->msg_format, msg_format, sizeof(z->msg_format));
+				AST_LIST_LOCK(&zones);
+				AST_LIST_INSERT_HEAD(&zones, z, list);
+				AST_LIST_UNLOCK(&zones);
+			} else {
+				ast_log(AST_LOG_WARNING, "Invalid timezone definition at line %d\n", var->lineno);
+				ast_free(z);
+			}
 		}
 		var = var->next;
 	}
diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 46c71db..9c25ed5 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -15277,7 +15277,7 @@
 			inside_range = 0;
 			len = 0;
 			/* Prepare nice string in channel_list[] */
-			for (i = 0; i < mfcr2->numchans; i++) {
+			for (i = 0; i < mfcr2->numchans && len < sizeof(channel_list) - 1; i++) {
 				struct dahdi_pvt *p = mfcr2->pvts[i];
 				if (!p) {
 					continue;
@@ -18263,13 +18263,17 @@
 		} else if (!strcasecmp(v->name, "namedpickupgroup")) {
 			confp->chan.named_pickupgroups = ast_get_namedgroups(v->value);
 		} else if (!strcasecmp(v->name, "setvar")) {
-			char *varname = ast_strdupa(v->value), *varval = NULL;
-			struct ast_variable *tmpvar;
-			if (varname && (varval = strchr(varname, '='))) {
-				*varval++ = '\0';
-				if ((tmpvar = ast_variable_new(varname, varval, ""))) {
-					tmpvar->next = confp->chan.vars;
-					confp->chan.vars = tmpvar;
+			if (v->value) {
+				char *varval = NULL;
+				struct ast_variable *tmpvar;
+				char varname[strlen(v->value) + 1];
+				strcpy(varname, v->value); /* safe */
+				if ((varval = strchr(varname, '='))) {
+					*varval++ = '\0';
+					if ((tmpvar = ast_variable_new(varname, varval, ""))) {
+						tmpvar->next = confp->chan.vars;
+						confp->chan.vars = tmpvar;
+					}
 				}
 			}
 		} else if (!strcasecmp(v->name, "immediate")) {
@@ -19213,9 +19217,12 @@
 			} else if (!strcasecmp(v->name, "mfcr2_logging")) {
 				openr2_log_level_t tmplevel;
 				char *clevel;
-				char *logval = ast_strdupa(v->value);
+				char *logval;
+				char copy[strlen(v->value) + 1];
+				strcpy(copy, v->value); /* safe */
+				logval = copy;
 				while (logval) {
- 					clevel = strsep(&logval,",");
+					clevel = strsep(&logval,",");
 					if (-1 == (tmplevel = openr2_log_get_level(clevel))) {
 						ast_log(LOG_WARNING, "Ignoring invalid logging level: '%s' at line %d.\n", clevel, v->lineno);
 						continue;
diff --git a/channels/chan_dahdi.h b/channels/chan_dahdi.h
index 6fcdb19..fab6be4 100644
--- a/channels/chan_dahdi.h
+++ b/channels/chan_dahdi.h
@@ -677,15 +677,15 @@
 	openr2_calling_party_category_t mfcr2_category;
 	int mfcr2_dnis_index;
 	int mfcr2_ani_index;
-	int mfcr2call:1;
-	int mfcr2_answer_pending:1;
-	int mfcr2_charge_calls:1;
-	int mfcr2_allow_collect_calls:1;
-	int mfcr2_forced_release:1;
-	int mfcr2_dnis_matched:1;
-	int mfcr2_call_accepted:1;
-	int mfcr2_accept_on_offer:1;
-	int mfcr2_progress_sent:1;
+	unsigned int mfcr2call:1;
+	unsigned int mfcr2_answer_pending:1;
+	unsigned int mfcr2_charge_calls:1;
+	unsigned int mfcr2_allow_collect_calls:1;
+	unsigned int mfcr2_forced_release:1;
+	unsigned int mfcr2_dnis_matched:1;
+	unsigned int mfcr2_call_accepted:1;
+	unsigned int mfcr2_accept_on_offer:1;
+	unsigned int mfcr2_progress_sent:1;
 #endif	/* defined(HAVE_OPENR2) */
 	/*! \brief DTMF digit in progress.  0 when no digit in progress. */
 	char begindigit;
diff --git a/channels/chan_motif.c b/channels/chan_motif.c
index 97a56d5..ffc6d12 100644
--- a/channels/chan_motif.c
+++ b/channels/chan_motif.c
@@ -2092,15 +2092,15 @@
 
 	/* Iterate the codecs updating the relevant RTP instance as we go */
 	for (codec = iks_child(description); codec; codec = iks_next(codec)) {
-		char *id = iks_find_attrib(codec, "id"), *name = iks_find_attrib(codec, "name");
+		char *id = iks_find_attrib(codec, "id"), *attr_name = iks_find_attrib(codec, "name");
 		char *clockrate = iks_find_attrib(codec, "clockrate");
 		int rtp_id, rtp_clockrate;
 
-		if (!ast_strlen_zero(id) && !ast_strlen_zero(name) && (sscanf(id, "%30d", &rtp_id) == 1)) {
+		if (!ast_strlen_zero(id) && !ast_strlen_zero(attr_name) && (sscanf(id, "%30d", &rtp_id) == 1)) {
 			if (!ast_strlen_zero(clockrate) && (sscanf(clockrate, "%30d", &rtp_clockrate) == 1)) {
-				ast_rtp_codecs_payloads_set_rtpmap_type_rate(&codecs, NULL, rtp_id, media, name, 0, rtp_clockrate);
+				ast_rtp_codecs_payloads_set_rtpmap_type_rate(&codecs, NULL, rtp_id, media, attr_name, 0, rtp_clockrate);
 			} else {
-				ast_rtp_codecs_payloads_set_rtpmap_type(&codecs, NULL, rtp_id, media, name, 0);
+				ast_rtp_codecs_payloads_set_rtpmap_type(&codecs, NULL, rtp_id, media, attr_name, 0);
 			}
 		}
 	}
diff --git a/codecs/ex_alaw.h b/codecs/ex_alaw.h
index e8629be..055583c 100644
--- a/codecs/ex_alaw.h
+++ b/codecs/ex_alaw.h
@@ -7,6 +7,9 @@
  *
  */
 
+#ifndef _ASTERISK_EX_ALAW_H
+#define _ASTERISK_EX_ALAW_H
+
 static uint8_t ex_alaw[] = {
 	0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x15,
 	0x10, 0x18, 0x1b, 0x1e, 0x21, 0x24, 0x27, 0x2a,
@@ -34,3 +37,5 @@
 	f.subclass.format = ast_format_alaw;
 	return &f;
 }
+
+#endif /* _ASTERISK_EX_ALAW_H */
diff --git a/codecs/ex_g722.h b/codecs/ex_g722.h
index 390cc7b..bd28543 100644
--- a/codecs/ex_g722.h
+++ b/codecs/ex_g722.h
@@ -7,6 +7,9 @@
  *
  */
 
+#ifndef _ASTERISK_EX_G722_H
+#define _ASTERISK_EX_G722_H
+
 static uint8_t ex_g722[] = {
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@@ -46,3 +49,5 @@
 
 	return &f;
 }
+
+#endif /* _ASTERISK_EX_G722_H */
diff --git a/codecs/ex_ulaw.h b/codecs/ex_ulaw.h
index d18a08e..6401033 100644
--- a/codecs/ex_ulaw.h
+++ b/codecs/ex_ulaw.h
@@ -7,6 +7,9 @@
  *
  */
 
+#ifndef _ASTERISK_EX_ULAW_H
+#define _ASTERISK_EX_ULAW_H
+
 static uint8_t ex_ulaw[] = {
 	0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x15,
 	0x10, 0x18, 0x1b, 0x1e, 0x21, 0x24, 0x27, 0x2a,
@@ -36,3 +39,5 @@
 
 	return &f;
 }
+
+#endif /* _ASTERISK_EX_ULAW_H */
diff --git a/formats/format_g726.c b/formats/format_g726.c
index 0f31db9..9a9e59a 100644
--- a/formats/format_g726.c
+++ b/formats/format_g726.c
@@ -201,7 +201,7 @@
 	return ftello(fs->f) << 1;
 }
 
-static struct ast_format_def f[] = {
+static struct ast_format_def f_def[] = {
 	{
 		.name = "g726-40",
 		.exts = "g726-40",
@@ -261,9 +261,9 @@
 {
 	int i;
 
-	for (i = 0; f[i].desc_size ; i++) {
-		if (ast_format_def_unregister(f[i].name))
-			ast_log(LOG_WARNING, "Failed to unregister format %s.\n", f[i].name);
+	for (i = 0; f_def[i].desc_size ; i++) {
+		if (ast_format_def_unregister(f_def[i].name))
+			ast_log(LOG_WARNING, "Failed to unregister format %s.\n", f_def[i].name);
 	}
 	return(0);
 }
@@ -272,10 +272,10 @@
 {
 	int i;
 
-	for (i = 0; f[i].desc_size ; i++) {
-		f[i].format = ast_format_g726;
-		if (ast_format_def_register(&f[i])) {	/* errors are fatal */
-			ast_log(LOG_WARNING, "Failed to register format %s.\n", f[i].name);
+	for (i = 0; f_def[i].desc_size ; i++) {
+		f_def[i].format = ast_format_g726;
+		if (ast_format_def_register(&f_def[i])) {	/* errors are fatal */
+			ast_log(LOG_WARNING, "Failed to register format %s.\n", f_def[i].name);
 			unload_module();
 			return AST_MODULE_LOAD_DECLINE;
 		}
diff --git a/formats/msgsm.h b/formats/msgsm.h
index bb46a3a..84789c3 100644
--- a/formats/msgsm.h
+++ b/formats/msgsm.h
@@ -1,4 +1,6 @@
 /* Conversion routines derived from code by guido at sienanet.it */
+#ifndef _ASTERISK_MSGSM_H
+#define _ASTERISK_MSGSM_H
 
 #define GSM_MAGIC 0xD
 
@@ -687,3 +689,5 @@
                         writeGSM_33(d+33);
 
 }
+
+#endif /* _ASTERISK_MSGSM_H */
diff --git a/include/asterisk/ari.h b/include/asterisk/ari.h
index f83df04..051df51 100644
--- a/include/asterisk/ari.h
+++ b/include/asterisk/ari.h
@@ -99,7 +99,7 @@
 	/*! Corresponding text for the response code */
 	const char *response_text; /* Shouldn't http.c handle this? */
 	/*! Flag to indicate that no further response is needed */
-	int no_response:1;
+	unsigned int no_response:1;
 };
 
 /*!
diff --git a/include/asterisk/calendar.h b/include/asterisk/calendar.h
index 2672293..d759e7c 100644
--- a/include/asterisk/calendar.h
+++ b/include/asterisk/calendar.h
@@ -132,8 +132,8 @@
 	int timeframe;       /*!< Span (in mins) of calendar data to pull with each request */
 	pthread_t thread;    /*!< The thread that the calendar is loaded/updated in */
 	ast_cond_t unload;
-	int unloading:1;
-	int pending_deletion:1; /*!< No longer used */
+	unsigned int unloading:1;
+	unsigned int pending_deletion:1; /*!< No longer used */
 	struct ao2_container *events;  /*!< The events that are known at this time */
 };
 
diff --git a/include/asterisk/channel_internal.h b/include/asterisk/channel_internal.h
index 2316e2f..ab80839 100644
--- a/include/asterisk/channel_internal.h
+++ b/include/asterisk/channel_internal.h
@@ -18,6 +18,9 @@
  * \brief Internal channel functions for channel.c to use
  */
 
+#ifndef _ASTERISK_CHANNEL_INTERNAL_H
+#define _ASTERISK_CHANNEL_INTERNAL_H
+
 #define ast_channel_internal_alloc(destructor, assignedid, requestor) __ast_channel_internal_alloc(destructor, assignedid, requestor, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 struct ast_channel *__ast_channel_internal_alloc(void (*destructor)(void *obj), const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *file, int line, const char *function);
 void ast_channel_internal_finalize(struct ast_channel *chan);
@@ -27,3 +30,5 @@
 
 void ast_channel_internal_errno_set(enum ast_channel_error error);
 enum ast_channel_error ast_channel_internal_errno(void);
+
+#endif /* _ASTERISK_CHANNEL_INTERNAL_H */
diff --git a/include/asterisk/config_options.h b/include/asterisk/config_options.h
index 420eb97..4429936 100644
--- a/include/asterisk/config_options.h
+++ b/include/asterisk/config_options.h
@@ -168,7 +168,7 @@
 
 struct aco_info {
 	const char *module; /*!< The name of the module whose config is being processed */
-	int hidden:1;                /*!< If enabled, this config item is hidden from users */
+	unsigned int hidden:1;                /*!< If enabled, this config item is hidden from users */
 	aco_pre_apply_config pre_apply_config; /*!< A callback called after processing, but before changes are applied */
 	aco_post_apply_config post_apply_config;/*!< A callback called after changes are applied */
 	aco_snapshot_alloc snapshot_alloc;     /*!< Allocate an object to hold all global configs and item containers */
diff --git a/include/asterisk/max_forwards.h b/include/asterisk/max_forwards.h
index 3130b4b..5d0c0d8 100644
--- a/include/asterisk/max_forwards.h
+++ b/include/asterisk/max_forwards.h
@@ -17,6 +17,7 @@
  */
 
 #ifndef MAX_FORWARDS_H
+#define MAX_FORWARDS_H
 
 struct ast_channel;
 
diff --git a/include/asterisk/mixmonitor.h b/include/asterisk/mixmonitor.h
index 892cd2a..6527d67 100644
--- a/include/asterisk/mixmonitor.h
+++ b/include/asterisk/mixmonitor.h
@@ -23,6 +23,9 @@
  * \author Jonathan Rose <jrose at digium.com>
  */
 
+#ifndef _ASTERISK_MIX_MONITOR_H
+#define _ASTERISK_MIX_MONITOR_H
+
 /*!
  * \brief Start a mixmonitor on a channel.
  * \since 12.0.0
@@ -103,3 +106,5 @@
  * \retval non-zero on failure
  */
 int ast_stop_mixmonitor(struct ast_channel *chan, const char *mixmon_id);
+
+#endif /* _ASTERISK_MIX_MONITOR_H */
diff --git a/include/asterisk/parking.h b/include/asterisk/parking.h
index afe12c9..aece0ae 100644
--- a/include/asterisk/parking.h
+++ b/include/asterisk/parking.h
@@ -23,6 +23,9 @@
  * \author Jonathan Rose <jrose at digium.com>
  */
 
+#ifndef _ASTERISK_PARKING_H
+#define _ASTERISK_PARKING_H
+
 #include "asterisk/stringfields.h"
 #include "asterisk/bridge.h"
 
@@ -294,3 +297,5 @@
  * \retval 1 if there is a parking provider regsistered
  */
 int ast_parking_provider_registered(void);
+
+#endif /* _ASTERISK_PARKING_H */
diff --git a/include/asterisk/res_pjsip_presence_xml.h b/include/asterisk/res_pjsip_presence_xml.h
index 55b79ad..9e5a8c1 100644
--- a/include/asterisk/res_pjsip_presence_xml.h
+++ b/include/asterisk/res_pjsip_presence_xml.h
@@ -30,6 +30,9 @@
  * This constant is useful to check against when trying to determine
  * if printing XML succeeded or failed.
  */
+#ifndef _ASTERISK_PJSIP_PRESENCE_XML_H
+#define _ASTERISK_PJSIP_PRESENCE_XML_H
+
 #define AST_PJSIP_XML_PROLOG_LEN 39
 
 /*!
@@ -115,3 +118,5 @@
 void ast_sip_presence_xml_find_node_attr(pj_pool_t* pool,
 		pj_xml_node *parent, const char *node_name, const char *attr_name,
 		pj_xml_node **node, pj_xml_attr **attr);
+
+#endif /* _ASTERISK_PJSIP_PRESENCE_XML_H */
diff --git a/include/asterisk/slin.h b/include/asterisk/slin.h
index 9766374..dd9c9cb 100644
--- a/include/asterisk/slin.h
+++ b/include/asterisk/slin.h
@@ -22,6 +22,9 @@
  * Samples were truncated at 160 and 320 bytes.
  */
 
+#ifndef _ASTERISK_SLIN_H
+#define _ASTERISK_SLIN_H
+
 static uint16_t ex_slin8[] = {
 	0x0002, 0xfffc, 0x0000, 0xfffe, 0x0000, 0xfffa, 0x002a, 0x007a,
 	0x003a, 0xffbe, 0xff76, 0xff84, 0x0016, 0x007e, 0x0096, 0x00d2,
@@ -91,3 +94,5 @@
 
 	return &f;
 }
+
+#endif /* _ASTERISK_SLIN_H */
diff --git a/main/app.c b/main/app.c
index 5fb81ba..4cd5934 100644
--- a/main/app.c
+++ b/main/app.c
@@ -1506,7 +1506,7 @@
 	char comment[256];
 	int x, fmtcnt = 1, res = -1, outmsg = 0;
 	struct ast_filestream *others[AST_MAX_FORMATS];
-	char *sfmt[AST_MAX_FORMATS];
+	const char *sfmt[AST_MAX_FORMATS];
 	char *stringp = NULL;
 	time_t start, end;
 	struct ast_dsp *sildet = NULL;   /* silence detector dsp */
@@ -1581,7 +1581,12 @@
 			ast_log(LOG_WARNING, "Please increase AST_MAX_FORMATS in file.h\n");
 			break;
 		}
-		sfmt[fmtcnt++] = ast_strdupa(fmt);
+		/*
+		 * Storage for 'fmt' is on the stack and held by 'fmts', which is maintained for
+		 * the rest of this function. So okay to not duplicate 'fmt' here, but only keep
+		 * a pointer to it.
+		 */
+		sfmt[fmtcnt++] = fmt;
 	}
 
 	end = start = time(NULL);  /* pre-initialize end to be same as start in case we never get into loop */
diff --git a/main/asterisk.c b/main/asterisk.c
index 30b84e6..8af5588 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -3647,11 +3647,12 @@
 int main(int argc, char *argv[])
 {
 	int c;
-	char * xarg = NULL;
 	int x;
 	int isroot = 1, rundir_exists = 0;
-	const char *runuser = NULL, *rungroup = NULL;
-	char *remotesock = NULL;
+	RAII_VAR(char *, runuser, NULL, ast_free);
+	RAII_VAR(char *, rungroup, NULL, ast_free);
+	RAII_VAR(char *, xarg, NULL, ast_free);
+	RAII_VAR(char *, remotesock, NULL, ast_free);
 	struct rlimit l;
 
 	/* Remember original args for restart */
@@ -3715,7 +3716,7 @@
 			break;
 #endif
 		case 'G':
-			rungroup = ast_strdupa(optarg);
+			rungroup = ast_strdup(optarg);
 			break;
 		case 'g':
 			ast_set_flag(&ast_options, AST_OPT_FLAG_DUMP_CORE);
@@ -3760,7 +3761,7 @@
 			ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
 			break;
 		case 's':
-			remotesock = ast_strdupa(optarg);
+			remotesock = ast_strdup(optarg);
 			break;
 		case 'T':
 			ast_set_flag(&ast_options, AST_OPT_FLAG_TIMESTAMP);
@@ -3769,7 +3770,7 @@
 			ast_set_flag(&ast_options, AST_OPT_FLAG_CACHE_RECORD_FILES);
 			break;
 		case 'U':
-			runuser = ast_strdupa(optarg);
+			runuser = ast_strdup(optarg);
 			break;
 		case 'V':
 			show_version();
@@ -3787,7 +3788,7 @@
 			ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
 
 			ast_set_flag(&ast_options, AST_OPT_FLAG_EXEC | AST_OPT_FLAG_NO_COLOR);
-			xarg = ast_strdupa(optarg);
+			xarg = ast_strdup(optarg);
 			break;
 		case '?':
 			exit(1);
@@ -3872,9 +3873,9 @@
 #endif /* !defined(CONFIGURE_RAN_AS_ROOT) */
 
 	if ((!rungroup) && !ast_strlen_zero(ast_config_AST_RUN_GROUP))
-		rungroup = ast_config_AST_RUN_GROUP;
+		rungroup = ast_strdup(ast_config_AST_RUN_GROUP);
 	if ((!runuser) && !ast_strlen_zero(ast_config_AST_RUN_USER))
-		runuser = ast_config_AST_RUN_USER;
+		runuser = ast_strdup(ast_config_AST_RUN_USER);
 
 	/* Must install this signal handler up here to ensure that if the canary
 	 * fails to execute that it doesn't kill the Asterisk process.
diff --git a/main/event.c b/main/event.c
index 019dfca..ef43b79 100644
--- a/main/event.c
+++ b/main/event.c
@@ -421,7 +421,7 @@
 		ie_type != AST_EVENT_IE_END;
 		ie_type = va_arg(ap, enum ast_event_ie_type))
 	{
-		struct ast_event_ie_val *ie_value = ast_alloca(sizeof(*ie_value));
+		struct ast_event_ie_val *ie_value = ast_malloc(sizeof(*ie_value));
 		int insert = 0;
 
 		memset(ie_value, 0, sizeof(*ie_value));
@@ -445,7 +445,7 @@
 		{
 			void *data = va_arg(ap, void *);
 			size_t datalen = va_arg(ap, size_t);
-			ie_value->payload.raw = ast_alloca(datalen);
+			ie_value->payload.raw = ast_malloc(datalen);
 			memcpy(ie_value->payload.raw, data, datalen);
 			ie_value->raw_datalen = datalen;
 			insert = 1;
@@ -493,7 +493,7 @@
 
 		/* realloc inside one of the append functions failed */
 		if (!event) {
-			return NULL;
+			goto cleanup;
 		}
 	}
 
@@ -503,6 +503,17 @@
 		ast_event_append_eid(&event);
 	}
 
+cleanup:
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&ie_vals, ie_val, entry) {
+		AST_LIST_REMOVE_CURRENT(entry);
+
+		if (ie_val->ie_pltype == AST_EVENT_IE_PLTYPE_RAW) {
+			ast_free(ie_val->payload.raw);
+		}
+		ast_free(ie_val);
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
+
 	return event;
 }
 
diff --git a/main/file.c b/main/file.c
index bb1db3e..7510007 100644
--- a/main/file.c
+++ b/main/file.c
@@ -516,7 +516,9 @@
 	AST_RWLIST_RDLOCK(&formats);
 	/* Check for a specific format */
 	AST_RWLIST_TRAVERSE(&formats, f, list) {
-		char *stringp, *ext = NULL;
+		char *ext = NULL;
+		char storage[strlen(f->exts) + 1];
+		char *stringp;
 
 		if (fmt && !exts_compare(f->exts, fmt))
 			continue;
@@ -525,7 +527,8 @@
 		 * The file must exist, and for OPEN, must match
 		 * one of the formats supported by the channel.
 		 */
-		stringp = ast_strdupa(f->exts);	/* this is in the stack so does not need to be freed */
+		strcpy(storage, f->exts); /* safe - this is in the stack so does not need to be freed */
+		stringp = storage;
 		while ( (ext = strsep(&stringp, "|")) ) {
 			struct stat st;
 			char *fn = build_filename(filename, ext);
@@ -1402,13 +1405,13 @@
 			  We touch orig_fn just as a place-holder so other things (like vmail) see the file is there.
 			  What we are really doing is writing to record_cache_dir until we are done then we will mv the file into place.
 			*/
-			orig_fn = ast_strdupa(fn);
+			orig_fn = ast_strdup(fn);
 			for (c = fn; *c; c++)
 				if (*c == '/')
 					*c = '_';
 
 			size = strlen(fn) + strlen(record_cache_dir) + 2;
-			buf = ast_alloca(size);
+			buf = ast_malloc(size);
 			strcpy(buf, record_cache_dir);
 			strcat(buf, "/");
 			strcat(buf, fn);
@@ -1439,14 +1442,18 @@
 				if (orig_fn) {
 					unlink(fn);
 					unlink(orig_fn);
+					ast_free(orig_fn);
 				}
 				if (fs) {
 					ast_closestream(fs);
 					fs = NULL;
 				}
-				if (!buf) {
-					ast_free(fn);
-				}
+				/*
+				 * 'fn' was has either been allocated from build_filename, or that was freed
+				 * and now 'fn' points to memory allocated for 'buf'. Either way the memory
+				 * now needs to be released.
+				 */
+				ast_free(fn);
 				continue;
 			}
 			fs->trans = NULL;
@@ -1454,8 +1461,14 @@
 			fs->flags = flags;
 			fs->mode = mode;
 			if (orig_fn) {
-				fs->realfilename = ast_strdup(orig_fn);
-				fs->filename = ast_strdup(fn);
+				fs->realfilename = orig_fn;
+				fs->filename = fn;
+				/*
+				 * The above now manages the memory allocated for 'orig_fn' and 'fn', so
+				 * set them to NULL, so they don't get released at the end of the loop.
+				 */
+				orig_fn = NULL;
+				fn = NULL;
 			} else {
 				fs->realfilename = NULL;
 				fs->filename = ast_strdup(filename);
@@ -1468,9 +1481,9 @@
 			if (orig_fn)
 				unlink(orig_fn);
 		}
-		/* if buf != NULL then fn is already free and pointing to it */
-		if (!buf)
-			ast_free(fn);
+		/* Free 'fn', or if 'fn' points to 'buf' then free 'buf' */
+		ast_free(fn);
+		ast_free(orig_fn);
 	}
 
 	AST_RWLIST_UNLOCK(&formats);
diff --git a/main/indications.c b/main/indications.c
index 622f98d..b264841 100644
--- a/main/indications.c
+++ b/main/indications.c
@@ -920,11 +920,11 @@
 	ast_copy_string(buf, val, sizeof(buf));
 
 	while ((ring = strsep(&c, ","))) {
-		int *tmp, val;
+		int *tmp, value;
 
 		ring = ast_strip(ring);
 
-		if (!isdigit(ring[0]) || (val = atoi(ring)) == -1) {
+		if (!isdigit(ring[0]) || (value = atoi(ring)) == -1) {
 			ast_log(LOG_WARNING, "Invalid ringcadence given '%s'.\n", ring);
 			continue;
 		}
@@ -934,7 +934,7 @@
 		}
 
 		zone->ringcadence = tmp;
-		tmp[zone->nrringcadence] = val;
+		tmp[zone->nrringcadence] = value;
 		zone->nrringcadence++;
 	}
 }
diff --git a/main/manager.c b/main/manager.c
index 1df6765..fc602bc 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -1615,7 +1615,7 @@
 	FILE *f;
 	int fd;
 	enum mansession_message_parsing parsing;
-	int write_error:1;
+	unsigned int write_error:1;
 	struct manager_custom_hook *hook;
 	ast_mutex_t lock;
 };
@@ -3808,8 +3808,8 @@
 		int allowdups = 0;
 		int istemplate = 0;
 		int ignoreerror = 0;
-		char *inherit = NULL;
-		char *catfilter = NULL;
+		RAII_VAR(char *, inherit, NULL, ast_free);
+		RAII_VAR(char *, catfilter, NULL, ast_free);
 		char *token;
 		int foundvar = 0;
 		int foundcat = 0;
@@ -3847,7 +3847,9 @@
 		snprintf(hdr, sizeof(hdr), "Options-%06d", x);
 		options = astman_get_header(m, hdr);
 		if (!ast_strlen_zero(options)) {
-			dupoptions = ast_strdupa(options);
+			char copy[strlen(options) + 1];
+			strcpy(copy, options); /* safe */
+			dupoptions = copy;
 			while ((token = ast_strsep(&dupoptions, ',', AST_STRSEP_STRIP))) {
 				if (!strcasecmp("allowdups", token)) {
 					allowdups = 1;
@@ -3865,7 +3867,7 @@
 					char *c = ast_strsep(&token, '=', AST_STRSEP_STRIP);
 					c = ast_strsep(&token, '=', AST_STRSEP_STRIP);
 					if (c) {
-						inherit = ast_strdupa(c);
+						inherit = ast_strdup(c);
 					}
 					continue;
 				}
@@ -3873,7 +3875,7 @@
 					char *c = ast_strsep(&token, '=', AST_STRSEP_STRIP);
 					c = ast_strsep(&token, '=', AST_STRSEP_STRIP);
 					if (c) {
-						catfilter = ast_strdupa(c);
+						catfilter = ast_strdup(c);
 					}
 					continue;
 				}
diff --git a/main/pbx_variables.c b/main/pbx_variables.c
index f09540b..88c4ec1 100644
--- a/main/pbx_variables.c
+++ b/main/pbx_variables.c
@@ -632,9 +632,8 @@
 	/* Substitutes variables into cp2, based on string cp1, cp2 NO LONGER NEEDS TO BE ZEROED OUT!!!!  */
 	const char *whereweare;
 	const char *orig_cp2 = cp2;
-	char *workspace = NULL;
-	char *ltmp = NULL;
-	char *var = NULL;
+	char ltmp[VAR_BUF_SIZE];
+	char var[VAR_BUF_SIZE];
 
 	*cp2 = 0; /* just in case nothing ends up there */
 	whereweare = cp1;
@@ -692,6 +691,7 @@
 			int offset2;
 			int isfunction;
 			char *cp4;
+			char workspace[VAR_BUF_SIZE] = "";
 
 			/* We have a variable.  Find the start and end, and determine
 			   if we are going to have to recursively call ourselves on the
@@ -727,28 +727,17 @@
 			/* Skip totally over variable string */
 			whereweare = vare;
 
-			if (!var)
-				var = ast_alloca(VAR_BUF_SIZE);
-
 			/* Store variable name expression to lookup (and truncate). */
 			ast_copy_string(var, vars, len + 1);
 
 			/* Substitute if necessary */
 			if (needsub) {
-				if (!ltmp) {
-					ltmp = ast_alloca(VAR_BUF_SIZE);
-				}
 				pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, NULL);
 				vars = ltmp;
 			} else {
 				vars = var;
 			}
 
-			if (!workspace)
-				workspace = ast_alloca(VAR_BUF_SIZE);
-
-			workspace[0] = '\0';
-
 			parse_variable_name(vars, &offset, &offset2, &isfunction);
 			if (isfunction) {
 				/* Evaluate function */
@@ -822,17 +811,11 @@
 			/* Skip totally over expression */
 			whereweare = vare;
 
-			if (!var)
-				var = ast_alloca(VAR_BUF_SIZE);
-
 			/* Store expression to evaluate (and truncate). */
 			ast_copy_string(var, vars, len + 1);
 
 			/* Substitute if necessary */
 			if (needsub) {
-				if (!ltmp) {
-					ltmp = ast_alloca(VAR_BUF_SIZE);
-				}
 				pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, NULL);
 				vars = ltmp;
 			} else {
diff --git a/main/stasis.c b/main/stasis.c
index 8cbfe724..e570748 100644
--- a/main/stasis.c
+++ b/main/stasis.c
@@ -305,7 +305,7 @@
 #define TOPIC_POOL_BUCKETS 57
 
 /*! Thread pool for topics that don't want a dedicated taskprocessor */
-static struct ast_threadpool *pool;
+static struct ast_threadpool *threadpool;
 
 STASIS_MESSAGE_TYPE_DEFN(stasis_subscription_change_type);
 
@@ -756,7 +756,7 @@
 		 * pool should be used.
 		 */
 		if (use_thread_pool) {
-			sub->mailbox = ast_threadpool_serializer(tps_name, pool);
+			sub->mailbox = ast_threadpool_serializer(tps_name, threadpool);
 		} else {
 			sub->mailbox = ast_taskprocessor_get(tps_name, TPS_REF_DEFAULT);
 		}
@@ -2728,8 +2728,8 @@
 	ao2_global_obj_release(subscription_statistics);
 	ao2_global_obj_release(topic_statistics);
 #endif
-	ast_threadpool_shutdown(pool);
-	pool = NULL;
+	ast_threadpool_shutdown(threadpool);
+	threadpool = NULL;
 	STASIS_MESSAGE_TYPE_CLEANUP(stasis_subscription_change_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_multi_user_event_type);
 	aco_info_destroy(&cfg_info);
@@ -2806,9 +2806,9 @@
 	threadpool_opts.auto_increment = 1;
 	threadpool_opts.max_size = cfg->threadpool_options->max_size;
 	threadpool_opts.idle_timeout = cfg->threadpool_options->idle_timeout_sec;
-	pool = ast_threadpool_create("stasis", NULL, &threadpool_opts);
+	threadpool = ast_threadpool_create("stasis", NULL, &threadpool_opts);
 	ao2_ref(cfg, -1);
-	if (!pool) {
+	if (!threadpool) {
 		ast_log(LOG_ERROR, "Failed to create 'stasis-core' threadpool\n");
 
 		return -1;
diff --git a/main/stasis_cache.c b/main/stasis_cache.c
index 0f2d443..0718f97 100644
--- a/main/stasis_cache.c
+++ b/main/stasis_cache.c
@@ -865,13 +865,13 @@
 		 * continue to grow unabated.
 		 */
 		if (strcmp(change->description, "Unsubscribe") == 0) {
-			struct stasis_cache_entry *sub;
+			struct stasis_cache_entry *cached_sub;
 
 			ao2_wrlock(caching_topic->cache->entries);
-			sub = cache_find(caching_topic->cache->entries, stasis_subscription_change_type(), change->uniqueid);
-			if (sub) {
-				ao2_cleanup(cache_remove(caching_topic->cache->entries, sub, stasis_message_eid(message)));
-				ao2_cleanup(sub);
+			cached_sub = cache_find(caching_topic->cache->entries, stasis_subscription_change_type(), change->uniqueid);
+			if (cached_sub) {
+				ao2_cleanup(cache_remove(caching_topic->cache->entries, cached_sub, stasis_message_eid(message)));
+				ao2_cleanup(cached_sub);
 			}
 			ao2_unlock(caching_topic->cache->entries);
 			ao2_cleanup(caching_topic_needs_unref);
diff --git a/res/ari/config.c b/res/ari/config.c
index 275f41d..713656b 100644
--- a/res/ari/config.c
+++ b/res/ari/config.c
@@ -165,7 +165,7 @@
 	.item_offset = offsetof(struct ast_ari_conf, users),
 };
 
-static struct aco_type *user[] = ACO_TYPES(&user_option);
+static struct aco_type *global_user[] = ACO_TYPES(&user_option);
 
 static void conf_general_dtor(void *obj)
 {
@@ -343,16 +343,16 @@
 		FLDSET(struct ast_ari_conf_general, write_timeout), 1, INT_MAX);
 
 	/* ARI type=user category options */
-	aco_option_register(&cfg_info, "type", ACO_EXACT, user, NULL,
+	aco_option_register(&cfg_info, "type", ACO_EXACT, global_user, NULL,
 		OPT_NOOP_T, 0, 0);
-	aco_option_register(&cfg_info, "read_only", ACO_EXACT, user,
+	aco_option_register(&cfg_info, "read_only", ACO_EXACT, global_user,
 		"no", OPT_BOOL_T, 1,
 		FLDSET(struct ast_ari_conf_user, read_only));
-	aco_option_register(&cfg_info, "password", ACO_EXACT, user,
+	aco_option_register(&cfg_info, "password", ACO_EXACT, global_user,
 		"", OPT_CHAR_ARRAY_T, 0,
 		FLDSET(struct ast_ari_conf_user, password), ARI_PASSWORD_LEN);
 	aco_option_register_custom(&cfg_info, "password_format", ACO_EXACT,
-		user, "plain",  password_format_handler, 0);
+		global_user, "plain",  password_format_handler, 0);
 
 	return process_config(0);
 }
diff --git a/res/parking/parking_bridge_features.c b/res/parking/parking_bridge_features.c
index cf5cc72..5a013ea 100644
--- a/res/parking/parking_bridge_features.c
+++ b/res/parking/parking_bridge_features.c
@@ -51,7 +51,7 @@
 struct parked_subscription_data {
 	struct transfer_channel_data *transfer_data;
 	char *parkee_uuid;
-	int hangup_after:1;
+	unsigned int hangup_after:1;
 	char parker_uuid[0];
 };
 
diff --git a/res/parking/res_parking.h b/res/parking/res_parking.h
index 6fbde09..c6e0830 100644
--- a/res/parking/res_parking.h
+++ b/res/parking/res_parking.h
@@ -23,6 +23,9 @@
  * \author Jonathan Rose <jrose at digium.com>
  */
 
+#ifndef _ASTERISK_RES_PARKING_H
+#define _ASTERISK_RES_PARKING_H
+
 #include "asterisk/pbx.h"
 #include "asterisk/bridge.h"
 #include "asterisk/parking.h"
@@ -570,3 +573,5 @@
  * \retval res_parking's ast_module
  */
 const struct ast_module_info *parking_get_module_info(void);
+
+#endif /* _ASTERISK_RES_PARKING_H */
diff --git a/res/res_config_curl.c b/res/res_config_curl.c
index 61b6245..fc7e894 100644
--- a/res/res_config_curl.c
+++ b/res/res_config_curl.c
@@ -158,7 +158,7 @@
 	for (field = fields; field; field = field->next) {
 		if (start) {
 			char *op;
-			initfield = ast_strdupa(field->name);
+			initfield = ast_strdup(field->name);
 			if ((op = strchr(initfield, ' ')))
 				*op = '\0';
 		}
@@ -174,6 +174,7 @@
 	ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
 
 	if (!(cfg = ast_config_new())) {
+		ast_free(initfield);
 		return NULL;
 	}
 
@@ -208,6 +209,8 @@
 		ast_category_append(cfg, cat);
 	}
 
+	ast_free(initfield);
+
 	return cfg;
 }
 
diff --git a/res/res_phoneprov.c b/res/res_phoneprov.c
index 7091b9b..13bac4de 100644
--- a/res/res_phoneprov.c
+++ b/res/res_phoneprov.c
@@ -608,13 +608,14 @@
 		if (!strcasecmp(v->name, "mime_type")) {
 			ast_string_field_set(profile, default_mime_type, v->value);
 		} else if (!strcasecmp(v->name, "setvar")) {
-			char *value_copy = ast_strdupa(v->value);
+			char value_copy[strlen(v->value) + 1];
 
 			AST_DECLARE_APP_ARGS(args,
 				AST_APP_ARG(varname);
 				AST_APP_ARG(varval);
 			);
 
+			strcpy(value_copy, v->value); /* safe */
 			AST_NONSTANDARD_APP_ARGS(args, value_copy, '=');
 			do {
 				if (ast_strlen_zero(args.varname) || ast_strlen_zero(args.varval))
@@ -630,7 +631,7 @@
 		} else {
 			struct phoneprov_file *pp_file;
 			char *file_extension;
-			char *value_copy = ast_strdupa(v->value);
+			char value_copy[strlen(v->value) + 1];
 
 			AST_DECLARE_APP_ARGS(args,
 				AST_APP_ARG(filename);
@@ -645,6 +646,7 @@
 			if ((file_extension = strrchr(pp_file->format, '.')))
 				file_extension++;
 
+			strcpy(value_copy, v->value); /* safe */
 			AST_STANDARD_APP_ARGS(args, value_copy);
 
 			/* Mime type order of preference
diff --git a/res/res_pjsip/config_system.c b/res/res_pjsip/config_system.c
index 52f66a5..716a6da 100644
--- a/res/res_pjsip/config_system.c
+++ b/res/res_pjsip/config_system.c
@@ -83,7 +83,7 @@
 	return system;
 }
 
-static int system_apply(const struct ast_sorcery *system_sorcery, void *obj)
+static int system_apply(const struct ast_sorcery *sorcery, void *obj)
 {
 	struct system_config *system = obj;
 	int min_timerb;
diff --git a/res/res_pjsip/config_transport.c b/res/res_pjsip/config_transport.c
index fed56f9..e4fc9ed 100644
--- a/res/res_pjsip/config_transport.c
+++ b/res/res_pjsip/config_transport.c
@@ -1158,10 +1158,19 @@
 	return error;
 }
 
+static void localnet_to_vl_append(struct ast_variable **head, struct ast_ha *ha)
+{
+	char str[MAX_OBJECT_FIELD];
+	const char *addr = ast_strdupa(ast_sockaddr_stringify_addr(&ha->addr));
+	snprintf(str, MAX_OBJECT_FIELD, "%s%s/%s", ha->sense == AST_SENSE_ALLOW ? "!" : "",
+			 addr, ast_sockaddr_stringify_addr(&ha->netmask));
+
+	ast_variable_list_append(head, ast_variable_new("local_net", str, ""));
+}
+
 static int localnet_to_vl(const void *obj, struct ast_variable **fields)
 {
 	const struct ast_sip_transport *transport = obj;
-	char str[MAX_OBJECT_FIELD];
 	struct ast_variable *head = NULL;
 	struct ast_ha *ha;
 	RAII_VAR(struct ast_sip_transport_state *, state, find_state_by_transport(transport), ao2_cleanup);
@@ -1171,11 +1180,7 @@
 	}
 
 	for (ha = state->localnet; ha; ha = ha->next) {
-		const char *addr = ast_strdupa(ast_sockaddr_stringify_addr(&ha->addr));
-		snprintf(str, MAX_OBJECT_FIELD, "%s%s/%s", ha->sense == AST_SENSE_ALLOW ? "!" : "",
-			addr, ast_sockaddr_stringify_addr(&ha->netmask));
-
-		ast_variable_list_append(&head, ast_variable_new("local_net", str, ""));
+		localnet_to_vl_append(&head, ha);
 	}
 
 	if (head) {
diff --git a/res/res_pjsip_endpoint_identifier_ip.c b/res/res_pjsip_endpoint_identifier_ip.c
index e79715b..ac4057b 100644
--- a/res/res_pjsip_endpoint_identifier_ip.c
+++ b/res/res_pjsip_endpoint_identifier_ip.c
@@ -551,20 +551,24 @@
 	return 0;
 }
 
-static int match_to_var_list(const void *obj, struct ast_variable **fields)
+static void match_to_var_list_append(struct ast_variable **head, struct ast_ha *ha)
 {
 	char str[MAX_OBJECT_FIELD];
+	const char *addr = ast_strdupa(ast_sockaddr_stringify_addr(&ha->addr));
+	snprintf(str, MAX_OBJECT_FIELD, "%s%s/%s", ha->sense == AST_SENSE_ALLOW ? "!" : "",
+			 addr, ast_sockaddr_stringify_addr(&ha->netmask));
+
+	ast_variable_list_append(head, ast_variable_new("match", str, ""));
+}
+
+static int match_to_var_list(const void *obj, struct ast_variable **fields)
+{
 	const struct ip_identify_match *identify = obj;
 	struct ast_variable *head = NULL;
 	struct ast_ha *ha = identify->matches;
 
 	for (; ha; ha = ha->next) {
-		const char *addr = ast_strdupa(ast_sockaddr_stringify_addr(&ha->addr));
-		snprintf(str, MAX_OBJECT_FIELD, "%s%s/%s", ha->sense == AST_SENSE_ALLOW ? "!" : "",
-			addr, ast_sockaddr_stringify_addr(&ha->netmask));
-
-		ast_variable_list_append(&head, ast_variable_new("match", str, ""));
-
+		match_to_var_list_append(&head, ha);
 	}
 
 	if (head) {
diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c
index 9024bdb..5963066 100644
--- a/res/res_pjsip_registrar.c
+++ b/res/res_pjsip_registrar.c
@@ -1029,9 +1029,9 @@
 		case AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME:
 			uri = pjsip_uri_get_uri(rdata->msg_info.to->uri);
 
-			domain_name = ast_alloca(uri->host.slen + 1);
+			domain_name = ast_malloc(uri->host.slen + 1);
 			ast_copy_pj_str(domain_name, &uri->host, uri->host.slen + 1);
-			username = ast_alloca(uri->user.slen + 1);
+			username = ast_malloc(uri->user.slen + 1);
 			ast_copy_pj_str(username, &uri->user, uri->user.slen + 1);
 
 			/*
@@ -1049,9 +1049,9 @@
 			while ((header = pjsip_msg_find_hdr(rdata->msg_info.msg, PJSIP_H_AUTHORIZATION,
 				header ? header->next : NULL))) {
 				if (header && !pj_stricmp2(&header->scheme, "digest")) {
-					username = ast_alloca(header->credential.digest.username.slen + 1);
+					username = ast_malloc(header->credential.digest.username.slen + 1);
 					ast_copy_pj_str(username, &header->credential.digest.username, header->credential.digest.username.slen + 1);
-					domain_name = ast_alloca(header->credential.digest.realm.slen + 1);
+					domain_name = ast_malloc(header->credential.digest.realm.slen + 1);
 					ast_copy_pj_str(domain_name, &header->credential.digest.realm, header->credential.digest.realm.slen + 1);
 
 					aor_name = find_aor_name(username, domain_name, endpoint->aors);
@@ -1069,6 +1069,9 @@
 		if (aor_name) {
 			break;
 		}
+
+		ast_free(domain_name);
+		ast_free(username);
 	}
 
 	if (ast_strlen_zero(aor_name) || !(aor = ast_sip_location_retrieve_aor(aor_name))) {
@@ -1079,6 +1082,8 @@
 			username ?: "", ast_sorcery_object_get_id(endpoint));
 	}
 	ast_free(aor_name);
+	ast_free(domain_name);
+	ast_free(username);
 	return aor;
 }
 
diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index cb68abe..7aa97b8 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -2674,11 +2674,11 @@
 		ao2_ref(ice, -1);
 		ao2_lock(instance);
 		if (status != PJ_SUCCESS) {
-			char buf[100];
+			char err_buf[100];
 
-			pj_strerror(status, buf, sizeof(buf));
+			pj_strerror(status, err_buf, sizeof(err_buf));
 			ast_log(LOG_WARNING, "PJ ICE Rx error status code: %d '%s'.\n",
-				(int)status, buf);
+				(int)status, err_buf);
 			return -1;
 		}
 		if (!rtp->passthrough) {
diff --git a/res/stasis/command.c b/res/stasis/command.c
index 024f02b..7dda999 100644
--- a/res/stasis/command.c
+++ b/res/stasis/command.c
@@ -39,7 +39,7 @@
 	void *data;
 	command_data_destructor_fn data_destructor;
 	int retval;
-	int is_done:1;
+	unsigned int is_done:1;
 };
 
 static void command_dtor(void *obj)
diff --git a/res/stasis/control.c b/res/stasis/control.c
index 4e2490d..dedf943 100644
--- a/res/stasis/control.c
+++ b/res/stasis/control.c
@@ -90,7 +90,7 @@
 	/*!
 	 * When set, /c app_stasis should exit and continue in the dialplan.
 	 */
-	int is_done:1;
+	unsigned int is_done:1;
 };
 
 static void control_dtor(void *obj)

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/13102
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: Id4a881686605d26c94ab5409bc70fcc21efacc25
Gerrit-Change-Number: 13102
Gerrit-PatchSet: 1
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20191023/02d96209/attachment-0001.html>


More information about the asterisk-code-review mailing list