diff options
author | Jenkins2 <jenkins2@gerrit.asterisk.org> | 2017-11-07 19:41:46 -0600 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2017-11-07 19:41:46 -0600 |
commit | ebd9e5c8c3fa2984515c7a7ad6905815eca8d598 (patch) | |
tree | b391c99aa6acc4a944d1344e7c063769785f3ac0 | |
parent | 13ffdfd96a45264e8230e2e61fb35861c1b314b3 (diff) | |
parent | f899368cd63e8558ead0f3d6eb1cee3d95f27b88 (diff) |
Merge "res_pjsip_config_wizard: Fix leaks and add check for malloc failure."
-rw-r--r-- | res/res_pjsip_config_wizard.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/res/res_pjsip_config_wizard.c b/res/res_pjsip_config_wizard.c index 1526dc2e2..3a761a7c7 100644 --- a/res/res_pjsip_config_wizard.c +++ b/res/res_pjsip_config_wizard.c @@ -1001,7 +1001,10 @@ static int wizard_apply_handler(const struct ast_sorcery *sorcery, struct object 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); + } } } @@ -1168,15 +1171,22 @@ static void wizard_mapped_observer(const char *name, struct ast_sorcery *sorcery /* 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); } } |