Skip to content

Commit

Permalink
dialplan: free allocated vars in case of errors
Browse files Browse the repository at this point in the history
(cherry picked from commit bd5873c)
  • Loading branch information
miconda committed Aug 30, 2017
1 parent c07e616 commit 58578c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/modules/dialplan/dialplan.c
Expand Up @@ -267,7 +267,7 @@ static int dp_update(struct sip_msg * msg, pv_spec_t * src, pv_spec_t * dest,

set_attr_pvar:

if(!attr_pvar)
if(attr_pvar==NULL || attrs==NULL)
return 0;

val.rs = *attrs;
Expand Down Expand Up @@ -393,8 +393,10 @@ static int dp_trans_fixup(void ** param, int param_no){
}else{
lstr.s = p; lstr.len = strlen(p);
dp_par->v.sp[0] = pv_cache_get(&lstr);
if (dp_par->v.sp[0]==NULL)
if (dp_par->v.sp[0]==NULL) {
pkg_free(dp_par);
goto error;
}

verify_par_type(param_no, dp_par->v.sp[0]);
dp_par->type = DP_VAL_SPEC;
Expand All @@ -410,14 +412,18 @@ static int dp_trans_fixup(void ** param, int param_no){

lstr.s = p; lstr.len = strlen(p);
dp_par->v.sp[0] = pv_cache_get(&lstr);
if(dp_par->v.sp[0]==NULL)
if(dp_par->v.sp[0]==NULL) {
pkg_free(dp_par);
goto error;
}

if (s != 0) {
lstr.s = s; lstr.len = strlen(s);
dp_par->v.sp[1] = pv_cache_get(&lstr);
if (dp_par->v.sp[1]==NULL)
if (dp_par->v.sp[1]==NULL) {
pkg_free(dp_par);
goto error;
}
verify_par_type(param_no, dp_par->v.sp[1]);
}

Expand Down
7 changes: 4 additions & 3 deletions src/modules/dialplan/dp_repl.c
Expand Up @@ -234,7 +234,7 @@ dpl_dyn_pcre_p dpl_dynamic_pcre_list(sip_msg_t *msg, str *expr)
l = pkg_malloc(sizeof(struct str_list));
if(l==NULL) {
PKG_MEM_ERROR;
return NULL;
goto error;
}
memset(l, 0, sizeof(struct str_list));
if(dpl_get_avp_values(msg, elem, avp_elem, &l)<0) {
Expand Down Expand Up @@ -342,8 +342,10 @@ struct subst_expr* repl_exp_parse(str subst)
rw_no = 0;

repl = p;
if((rw_no = parse_repl(rw, &p, end, &max_pmatch, WITHOUT_SEP))< 0)
if((rw_no = parse_repl(rw, &p, end, &max_pmatch, WITHOUT_SEP))< 0) {
LM_ERR("parse repl failed\n");
goto error;
}

repl_end=p;

Expand Down Expand Up @@ -378,7 +380,6 @@ struct subst_expr* repl_exp_parse(str subst)
error:
if(shms.s != NULL)
shm_free(shms.s);
if (se) { repl_expr_free(se);}
return NULL;
}

Expand Down

0 comments on commit 58578c2

Please sign in to comment.