dialplan: free allocated vars in case of errors
authorDaniel-Constantin Mierla <miconda@gmail.com>
Fri, 21 Jul 2017 06:56:10 +0000 (08:56 +0200)
committerDaniel-Constantin Mierla <miconda@gmail.com>
Fri, 21 Jul 2017 06:56:10 +0000 (08:56 +0200)
src/modules/dialplan/dialplan.c
src/modules/dialplan/dp_repl.c

index b319607..e5710fd 100644 (file)
@@ -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;
@@ -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;
@@ -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]);
                }
 
index 2c0d9b3..8574167 100644 (file)
@@ -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) {
@@ -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;
 
@@ -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;
 }