]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: actions: add new function free_act_rule() to free a single rule
authorWilly Tarreau <w@1wt.eu>
Thu, 17 Mar 2022 19:23:43 +0000 (20:23 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 17 Mar 2022 19:26:19 +0000 (20:26 +0100)
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.

include/haproxy/action.h
src/action.c

index 5d751ac42b247e9b95cc4b56af049999f2abb640..eed440d8e3214edeb7baeeacde52781a20cfc872 100644 (file)
@@ -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)
 {
index 1de97692eea3fe750e737ab568d46203aba933ad..d4aecc8c0f3044178180eada5880bf328de07299 100644 (file)
@@ -301,16 +301,22 @@ struct act_rule *new_act_rule(enum act_from from, const char *file, int linenum)
        return rule;
 }
 
+/* fees rule <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);
        }
 }