[Asterisk-code-review] res pjsip config wizard: Fix leaks and add check for malloc ... (asterisk[13])

Jenkins2 asteriskteam at digium.com
Tue Nov 7 22:48:08 CST 2017


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/7075 )

Change subject: res_pjsip_config_wizard: Fix leaks and add check for malloc failure.
......................................................................

res_pjsip_config_wizard: Fix leaks and add check for malloc failure.

wizard_apply_handler():
- Free host if we fail to add it to the vector.

wizard_mapped_observer():
- Check for otw allocation failure.
- Free otw if we fail to add it to the vector.

Change-Id: Ib5d3bcabbd9c24dd8a3c9cc692a794a5f60243ad
---
M res/res_pjsip_config_wizard.c
1 file changed, 13 insertions(+), 3 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, but someone else must approve
  Richard Mudgett: Looks good to me, approved
  Jenkins2: Approved for Submit



diff --git a/res/res_pjsip_config_wizard.c b/res/res_pjsip_config_wizard.c
index c13ff4a..d487c4d 100644
--- a/res/res_pjsip_config_wizard.c
+++ b/res/res_pjsip_config_wizard.c
@@ -1003,7 +1003,10 @@
 		char *hosts = ast_strdupa(remote_hosts);
 
 		while ((host = ast_strsep(&hosts, ',', AST_STRSEP_TRIM))) {
-			AST_VECTOR_APPEND(&remote_hosts_vector, ast_strdup(host));
+			host = ast_strdup(host);
+			if (host && AST_VECTOR_APPEND(&remote_hosts_vector, host)) {
+				ast_free(host);
+			}
 		}
 	}
 
@@ -1170,15 +1173,22 @@
 	/* We're only interested in memory wizards with the pjsip_wizard tag. */
 	if (wizard_args && !strcmp(wizard_args, "pjsip_wizard")) {
 		otw = ast_malloc(sizeof(*otw) + strlen(object_type) + 1);
+		if (!otw) {
+			return;
+		}
+
 		otw->sorcery = sorcery;
 		otw->wizard = wizard;
 		otw->wizard_data = wizard_data;
 		otw->last_config = NULL;
 		strcpy(otw->object_type, object_type); /* Safe */
 		AST_VECTOR_RW_WRLOCK(&object_type_wizards);
-		AST_VECTOR_APPEND(&object_type_wizards, otw);
+		if (AST_VECTOR_APPEND(&object_type_wizards, otw)) {
+			ast_free(otw);
+		} else {
+			ast_debug(1, "Wizard mapped for object_type '%s'\n", object_type);
+		}
 		AST_VECTOR_RW_UNLOCK(&object_type_wizards);
-		ast_debug(1, "Wizard mapped for object_type '%s'\n", object_type);
 	}
 }
 

-- 
To view, visit https://gerrit.asterisk.org/7075
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib5d3bcabbd9c24dd8a3c9cc692a794a5f60243ad
Gerrit-Change-Number: 7075
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171107/13c85831/attachment.html>


More information about the asterisk-code-review mailing list