]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tree-wide: use free_acl_cond() where relevant
authorAurelien DARRAGON <adarragon@haproxy.com>
Thu, 11 May 2023 10:29:51 +0000 (12:29 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 11 May 2023 13:37:04 +0000 (15:37 +0200)
Now that we have free_acl_cond(cond) function that does cond prune then
frees cond, replace all occurences of this pattern:

   | prune_acl_cond(cond)
   | free(cond)

with:

   | free_acl_cond(cond)

addons/ot/src/conf.c
src/acl.c
src/cfgparse-listen.c
src/fcgi-app.c
src/flt_spoe.c
src/http_rules.c
src/proxy.c

index d575e3a04e290a3833e1d19ff91296037c5062df..2f667a42c15e73a0fbcd3a3d8a721de5f9b30629 100644 (file)
@@ -528,10 +528,7 @@ void flt_ot_conf_scope_free(struct flt_ot_conf_scope **ptr)
                FLT_OT_LIST_DEL(&(acl->list));
                FLT_OT_FREE(acl);
        }
-       if ((*ptr)->cond != NULL) {
-               prune_acl_cond((*ptr)->cond);
-               FLT_OT_FREE((*ptr)->cond);
-       }
+       free_acl_cond((*ptr)->cond);
        FLT_OT_LIST_DESTROY(context, &((*ptr)->contexts));
        FLT_OT_LIST_DESTROY(span, &((*ptr)->spans));
        FLT_OT_LIST_DESTROY(str, &((*ptr)->finish));
index 84cb0f0d8ad06ca1d2b146d9373023328cee71b9..1683fc04e571fbaaf48aab14c2c4f47574622807 100644 (file)
--- a/src/acl.c
+++ b/src/acl.c
@@ -1007,8 +1007,7 @@ struct acl_cond *parse_acl_cond(const char **args, struct list *known_acl,
  out_free_term:
        free(cur_term);
  out_free_suite:
-       prune_acl_cond(cond);
-       free(cond);
+       free_acl_cond(cond);
  out_return:
        return NULL;
 }
@@ -1337,6 +1336,7 @@ void acl_dump_kwd(void)
        }
 }
 
+/* Purge everything in the acl_cond <cond>, then free <cond> */
 void free_acl_cond(struct acl_cond *cond)
 {
        struct acl_term_suite *suite, *suiteb;
index 485b0b36c3d6b306c20b144619b7a9ed4e2c7487..3864a11c8986c586240d4fc95465cd093385be32 100644 (file)
@@ -1408,9 +1408,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                rule->file = strdup(file);
                if (!rule->file) {
                  use_backend_alloc_error:
-                       if (cond)
-                               prune_acl_cond(cond);
-                       ha_free(&cond);
+                       free_acl_cond(cond);
                        if (rule)
                                ha_free(&(rule->be.name));
                        ha_free(&rule);
@@ -1464,9 +1462,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
                rule->file = strdup(file);
                if (!rule->file) {
                  use_server_alloc_error:
-                       if (cond)
-                               prune_acl_cond(cond);
-                       ha_free(&cond);
+                       free_acl_cond(cond);
                        if (rule)
                                ha_free(&(rule->srv.name));
                        ha_free(&rule);
@@ -1510,9 +1506,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
 
                rule = calloc(1, sizeof(*rule));
                if (!rule) {
-                       if (cond)
-                               prune_acl_cond(cond);
-                       ha_free(&cond);
+                       free_acl_cond(cond);
                        goto alloc_error;
                }
                rule->cond = cond;
@@ -1678,9 +1672,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
 
                rule = calloc(1, sizeof(*rule));
                if (!rule) {
-                       if (cond)
-                               prune_acl_cond(cond);
-                       ha_free(&cond);
+                       free_acl_cond(cond);
                        goto alloc_error;
                }
                rule->cond = cond;
@@ -1733,9 +1725,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
 
                        rule = calloc(1, sizeof(*rule));
                        if (!rule) {
-                               if (cond)
-                                       prune_acl_cond(cond);
-                               ha_free(&cond);
+                               free_acl_cond(cond);
                                goto alloc_error;
                        }
                        rule->cond = cond;
index 1ece72b25818b55e0816f5032ab7e9ae463e7ccc..e0f3232f9ccd123e63ea0686910cda0085ef1eb9 100644 (file)
@@ -125,10 +125,7 @@ static void fcgi_release_rule_conf(struct fcgi_rule_conf *rule)
                return;
        free(rule->name);
        free(rule->value);
-       if (rule->cond) {
-               prune_acl_cond(rule->cond);
-               free(rule->cond);
-       }
+       free_acl_cond(rule->cond);
        free(rule);
 }
 
@@ -760,10 +757,7 @@ static int fcgi_app_add_rule(struct fcgi_app *curapp, enum fcgi_rule_type type,
                free(rule->value);
                free(rule);
        }
-       if (cond) {
-               prune_acl_cond(cond);
-               free(cond);
-       }
+       free_acl_cond(cond);
        memprintf(err, "out of memory");
        return 0;
 }
index 301d950bdac170fbb9d8595d3c8d9b818ee34db0..8d31780db71199b8e5ef15eb3a505c6819af8414 100644 (file)
@@ -141,10 +141,7 @@ spoe_release_message(struct spoe_message *msg)
                prune_acl(acl);
                free(acl);
        }
-       if (msg->cond) {
-               prune_acl_cond(msg->cond);
-               free(msg->cond);
-       }
+       free_acl_cond(msg->cond);
        free(msg);
 }
 
index 1efba4a98bd46f62bea65fd5fb98d06b33b67cf7..192f0c7d3768cd37b5ef1bb34f8f907524ebac78 100644 (file)
@@ -322,10 +322,7 @@ void http_free_redirect_rule(struct redirect_rule *rdr)
 {
        struct logformat_node *lf, *lfb;
 
-       if (rdr->cond) {
-               prune_acl_cond(rdr->cond);
-               free(rdr->cond);
-       }
+       free_acl_cond(rdr->cond);
        free(rdr->rdr_str);
        free(rdr->cookie_str);
        list_for_each_entry_safe(lf, lfb, &rdr->rdr_fmt, list) {
@@ -519,8 +516,7 @@ struct redirect_rule *http_parse_redirect_rule(const char *file, int linenum, st
                http_free_redirect_rule(rule);
        else if (cond) {
                /* rule not yet allocated, but cond already is */
-               prune_acl_cond(cond);
-               free(cond);
+               free_acl_cond(cond);
        }
 
        return NULL;
index 632d23e4966e7ff80c987cc6272565ccbaa9766a..d2f10936652cf9447c324af1021feab2576caac7 100644 (file)
@@ -200,8 +200,7 @@ void free_proxy(struct proxy *p)
 
        list_for_each_entry_safe(cond, condb, &p->mon_fail_cond, list) {
                LIST_DELETE(&cond->list);
-               prune_acl_cond(cond);
-               free(cond);
+               free_acl_cond(cond);
        }
 
        EXTRA_COUNTERS_FREE(p->extra_counters_fe);
@@ -215,7 +214,7 @@ void free_proxy(struct proxy *p)
 
        list_for_each_entry_safe(srule, sruleb, &p->server_rules, list) {
                LIST_DELETE(&srule->list);
-               prune_acl_cond(srule->cond);
+               free_acl_cond(srule->cond);
                list_for_each_entry_safe(lf, lfb, &srule->expr, list) {
                        LIST_DELETE(&lf->list);
                        release_sample_expr(lf->expr);
@@ -223,16 +222,12 @@ void free_proxy(struct proxy *p)
                        free(lf);
                }
                free(srule->file);
-               free(srule->cond);
                free(srule);
        }
 
        list_for_each_entry_safe(rule, ruleb, &p->switching_rules, list) {
                LIST_DELETE(&rule->list);
-               if (rule->cond) {
-                       prune_acl_cond(rule->cond);
-                       free(rule->cond);
-               }
+               free_acl_cond(rule->cond);
                free(rule->file);
                free(rule);
        }