From 476e5d0e03e47c8f606ba2e8c13a05570ce7b7d4 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 26 Oct 2016 11:34:47 +0200 Subject: [PATCH] REORG: sample: move code to release a sample expression in sample.c This code has been moved from haproxy.c to sample.c and the function release_sample_expr can now be called from anywhere to release a sample expression. This function will be used by the stream processing offload engine (SPOE). --- include/proto/sample.h | 1 + src/haproxy.c | 35 +---------------------------------- src/sample.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 34 deletions(-) diff --git a/include/proto/sample.h b/include/proto/sample.h index ecb2eb4977..4319278a9c 100644 --- a/include/proto/sample.h +++ b/include/proto/sample.h @@ -36,6 +36,7 @@ struct sample *sample_process(struct proxy *px, struct session *sess, struct sample *sample_fetch_as_type(struct proxy *px, struct session *sess, struct stream *strm, unsigned int opt, struct sample_expr *expr, int smp_type); +void release_sample_expr(struct sample_expr *expr); void sample_register_fetches(struct sample_fetch_kw_list *psl); void sample_register_convs(struct sample_conv_kw_list *psl); const char *sample_src_names(unsigned int use); diff --git a/src/haproxy.c b/src/haproxy.c index b899c76e43..c40813b246 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1342,33 +1342,6 @@ static void deinit_tcp_rules(struct list *rules) } } -static void deinit_sample_arg(struct arg *p) -{ - struct arg *p_back = p; - - if (!p) - return; - - while (p->type != ARGT_STOP) { - if (p->type == ARGT_STR || p->unresolved) { - free(p->data.str.str); - p->data.str.str = NULL; - p->unresolved = 0; - } - else if (p->type == ARGT_REG) { - if (p->data.reg) { - regex_free(p->data.reg); - free(p->data.reg); - p->data.reg = NULL; - } - } - p++; - } - - if (p_back != empty_arg_list) - free(p_back); -} - static void deinit_stick_rules(struct list *rules) { struct sticking_rule *rule, *ruleb; @@ -1376,13 +1349,7 @@ static void deinit_stick_rules(struct list *rules) list_for_each_entry_safe(rule, ruleb, rules, list) { LIST_DEL(&rule->list); deinit_acl_cond(rule->cond); - if (rule->expr) { - struct sample_conv_expr *conv_expr, *conv_exprb; - list_for_each_entry_safe(conv_expr, conv_exprb, &rule->expr->conv_exprs, list) - deinit_sample_arg(conv_expr->arg_p); - deinit_sample_arg(rule->expr->arg_p); - free(rule->expr); - } + release_sample_expr(rule->expr); free(rule); } } diff --git a/src/sample.c b/src/sample.c index 1438ca1146..35b5913bed 100644 --- a/src/sample.c +++ b/src/sample.c @@ -1382,6 +1382,46 @@ struct sample *sample_fetch_as_type(struct proxy *px, struct session *sess, return smp; } +static void release_sample_arg(struct arg *p) +{ + struct arg *p_back = p; + + if (!p) + return; + + while (p->type != ARGT_STOP) { + if (p->type == ARGT_STR || p->unresolved) { + free(p->data.str.str); + p->data.str.str = NULL; + p->unresolved = 0; + } + else if (p->type == ARGT_REG) { + if (p->data.reg) { + regex_free(p->data.reg); + free(p->data.reg); + p->data.reg = NULL; + } + } + p++; + } + + if (p_back != empty_arg_list) + free(p_back); +} + +void release_sample_expr(struct sample_expr *expr) +{ + struct sample_conv_expr *conv_expr, *conv_exprb; + + if (!expr) + return; + + list_for_each_entry_safe(conv_expr, conv_exprb, &expr->conv_exprs, list) + release_sample_arg(conv_expr->arg_p); + release_sample_arg(expr->arg_p); + free(expr); +} + /*****************************************************************/ /* Sample format convert functions */ /* These functions set the data type on return. */