MINOR: uri_auth: add stats_uri_auth_free helper

Let's now leverage stats_uri_auth_free() helper to free uri_auth struct
instead of manually performing the cleanup, which is error-prone.
This commit is contained in:
Aurelien DARRAGON 2024-11-13 19:14:10 +01:00
parent 350a3ab052
commit e1ec37ea51
3 changed files with 34 additions and 27 deletions

View 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 */

View 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);

View File

@ -13,7 +13,10 @@
#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