From: Willy Tarreau Date: Thu, 17 Mar 2022 19:23:43 +0000 (+0100) Subject: MINOR: actions: add new function free_act_rule() to free a single rule X-Git-Tag: v2.6-dev4~61 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6a783e499c8d5a7a3a2cd8eccd8faf4c8828a8f3;p=thirdparty%2Fhaproxy.git MINOR: actions: add new function free_act_rule() to free a single rule There was free_act_rules() that frees all rules from a head but nothing to free a single rule. Currently some rulesets partially free their own rules on parsing error, and we're seeing some regtests emit errors under ASAN because of this. Let's first extract the code to free a rule into its own function so that it becomes possible to use it on a single rule. --- diff --git a/include/haproxy/action.h b/include/haproxy/action.h index 5d751ac42b..eed440d8e3 100644 --- a/include/haproxy/action.h +++ b/include/haproxy/action.h @@ -34,6 +34,7 @@ struct dns_counters; int act_resolution_cb(struct resolv_requester *requester, struct dns_counters *counters); int act_resolution_error_cb(struct resolv_requester *requester, int error_code); const char *action_suggest(const char *word, const struct list *keywords, const char **extra); +void free_act_rule(struct act_rule *rule); static inline struct action_kw *action_lookup(struct list *keywords, const char *kw) { diff --git a/src/action.c b/src/action.c index 1de97692ee..d4aecc8c0f 100644 --- a/src/action.c +++ b/src/action.c @@ -301,16 +301,22 @@ struct act_rule *new_act_rule(enum act_from from, const char *file, int linenum) return rule; } +/* fees rule and its elements as well as the condition */ +void free_act_rule(struct act_rule *rule) +{ + LIST_DELETE(&rule->list); + free_acl_cond(rule->cond); + if (rule->release_ptr) + rule->release_ptr(rule); + free(rule->conf.file); + free(rule); +} + void free_act_rules(struct list *rules) { struct act_rule *rule, *ruleb; list_for_each_entry_safe(rule, ruleb, rules, list) { - LIST_DELETE(&rule->list); - free_acl_cond(rule->cond); - if (rule->release_ptr) - rule->release_ptr(rule); - free(rule->conf.file); - free(rule); + free_act_rule(rule); } }