]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: uri_auth: add stats_uri_auth_free helper
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 13 Nov 2024 18:14:10 +0000 (19:14 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 14 Nov 2024 14:03:33 +0000 (15:03 +0100)
Let's now leverage stats_uri_auth_free() helper to free uri_auth struct
instead of manually performing the cleanup, which is error-prone.

include/haproxy/uri_auth.h
src/haproxy.c
src/uri_auth.c

index 27dca02c707548be3972a46846db48c3bdcc72b6..ae5dbb04a0c2c3582319c9f9d194e33199b87ee2 100644 (file)
@@ -33,6 +33,7 @@ struct uri_auth *stats_add_auth(struct uri_auth **root, char *user);
 struct uri_auth *stats_add_scope(struct uri_auth **root, char *scope);
 struct uri_auth *stats_set_node(struct uri_auth **root, char *name);
 struct uri_auth *stats_set_desc(struct uri_auth **root, char *desc);
+void stats_uri_auth_free(struct uri_auth *uri_auth);
 
 #endif /* _HAPROXY_URI_AUTH_H */
 
index 3496ba8151748682a58f5059988c2b4e1aa2a59a..56bd38b4651402554325230bbbcfc55ba087ca17 100644 (file)
@@ -3283,35 +3283,9 @@ void deinit(void)
        proxy_destroy_all_unref_defaults();
 
        while (ua) {
-               struct stat_scope *scope, *scopep;
-               struct stats_admin_rule *rule, *ruleb;
-
                uap = ua;
                ua = ua->next;
-
-               free(uap->uri_prefix);
-               free(uap->auth_realm);
-               free(uap->node);
-               free(uap->desc);
-
-               userlist_free(uap->userlist);
-               free_act_rules(&uap->http_req_rules);
-               list_for_each_entry_safe(rule, ruleb, &uap->admin_rules, list) {
-                       LIST_DELETE(&rule->list);
-                       free_acl_cond(rule->cond);
-                       free(rule);
-               }
-
-               scope = uap->scope;
-               while (scope) {
-                       scopep = scope;
-                       scope = scope->next;
-
-                       free(scopep->px_id);
-                       free(scopep);
-               }
-
-               free(uap);
+               stats_uri_auth_free(uap);
        }
 
        userlist_free(userlist);
index 979b327f6afb3726a2d9ae881ce9d8380e15501d..a487ed3755624e79dde8b4fa32fc8302af394563 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
+#include <haproxy/acl.h>
+#include <haproxy/action.h>
 #include <haproxy/api.h>
+#include <haproxy/auth.h>
 #include <haproxy/base64.h>
 #include <haproxy/errors.h>
 #include <haproxy/list.h>
@@ -310,6 +313,35 @@ struct uri_auth *stats_add_scope(struct uri_auth **root, char *scope)
        return NULL;
 }
 
+void stats_uri_auth_free(struct uri_auth *uri_auth)
+{
+       struct stat_scope *scope, *scopep;
+       struct stats_admin_rule *rule, *ruleb;
+
+       free(uri_auth->uri_prefix);
+       free(uri_auth->auth_realm);
+       free(uri_auth->node);
+       free(uri_auth->desc);
+
+       userlist_free(uri_auth->userlist);
+       free_act_rules(&uri_auth->http_req_rules);
+       list_for_each_entry_safe(rule, ruleb, &uri_auth->admin_rules, list) {
+               LIST_DELETE(&rule->list);
+               free_acl_cond(rule->cond);
+               free(rule);
+       }
+
+       scope = uri_auth->scope;
+       while (scope) {
+               scopep = scope;
+               scope = scope->next;
+               free(scopep->px_id);
+               free(scopep);
+       }
+
+       free(uri_auth);
+}
+
 /*
  * Local variables:
  *  c-indent-level: 8