Skip to content

Commit

Permalink
core: rvalue - function to destroy content of rval without freeing it
Browse files Browse the repository at this point in the history
- needed in case of rval reuse in rve_replace_with_val()
  • Loading branch information
miconda committed Apr 6, 2021
1 parent 4f7b553 commit e770e0a
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions src/core/rvalue.c
Expand Up @@ -112,10 +112,7 @@ inline static void rval_force_clean(struct rvalue* rv)



/** frees a rval returned by rval_new(), rval_convert() or rval_expr_eval().
* Note: it will be freed only when refcnt reaches 0
*/
void rval_destroy(struct rvalue* rv)
static inline void rval_destroy_helper(struct rvalue* rv, int allocated)
{
if (rv && rv_unref(rv)){
rval_force_clean(rv);
Expand All @@ -126,13 +123,38 @@ void rval_destroy(struct rvalue* rv)
regfree(rv->v.re.regex);
}
if (rv->flags & RV_RV_ALLOCED_F){
pkg_free(rv);
if(likely(allocated)) {
pkg_free(rv);
} else {
/* not expected to be allocated */
abort(); /* abort, otherwise is lost - find bugs quicker */
}
}
}
}



/** frees a rval returned by rval_new(), rval_convert() or rval_expr_eval().
* Note: it will be freed only when refcnt reaches 0
*/
void rval_destroy(struct rvalue* rv)
{
rval_destroy_helper(rv, 1);
}



/** frees content of rval which is not allocated, otherwise aborts.
* Note: it will be freed only when refcnt reaches 0
*/
void rval_destroy_content(struct rvalue* rv)
{
rval_destroy_helper(rv, 0);
}



void rval_clean(struct rvalue* rv)
{
if (rv_unref(rv))
Expand Down Expand Up @@ -1523,7 +1545,7 @@ inline static int int_strop1(int* res, enum rval_expr_op op, str* s1)
}



#if 0
/** integer operation: ret= op v (returns a rvalue).
* @return rvalue on success, 0 on error
*/
Expand Down Expand Up @@ -1619,7 +1641,7 @@ inline static struct rvalue* rval_intop2(struct run_act_ctx* h,
rval_destroy(rv2);
return 0;
}

#endif /* #if 0 */


/** string add operation: ret= l . r (returns a rvalue).
Expand Down Expand Up @@ -3024,7 +3046,7 @@ static int rve_replace_with_val(struct rval_expr* rve, enum rval_type type,
refcnt=rve->left.rval.refcnt;
abort(); /* find bugs quicker -- andrei */
}
rval_destroy(&rve->left.rval);
rval_destroy_content(&rve->left.rval);
}
rval_init(&rve->left.rval, type, v, flags);
rve->left.rval.refcnt=refcnt;
Expand Down Expand Up @@ -3096,15 +3118,15 @@ static int fix_match_rve(struct rval_expr* rve)
/* fixup the right side (RE) */
if (rve_is_constant(rve->right.rve)){
if ((rve_guess_type(rve->right.rve)!=RV_STR)){
LM_ERR("fixup failure(%d,%d-%d,%d): left side of =~ is not string"
LM_ERR("fixup failure(%d,%d-%d,%d): right side of =~ is not string"
" (%d,%d)\n", rve->fpos.s_line, rve->fpos.s_col,
rve->fpos.e_line, rve->fpos.e_col,
rve->right.rve->fpos.s_line,
rve->right.rve->fpos.s_col);
goto error;
}
if ((rv=rval_expr_eval(0, 0, rve->right.rve))==0){
LM_ERR("fixup failure(%d,%d-%d,%d): bad RE expression\n",
LM_ERR("fixup failure(%d,%d-%d,%d): bad RE expression\n",
rve->right.rve->fpos.s_line, rve->right.rve->fpos.s_col,
rve->right.rve->fpos.e_line, rve->right.rve->fpos.e_col);
goto error;
Expand Down

0 comments on commit e770e0a

Please sign in to comment.