Skip to content

Commit e1ec37e

Browse files
committed
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.
1 parent 350a3ab commit e1ec37e

File tree

3 files changed

+34
-27
lines changed

3 files changed

+34
-27
lines changed

include/haproxy/uri_auth.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct uri_auth *stats_add_auth(struct uri_auth **root, char *user);
3333
struct uri_auth *stats_add_scope(struct uri_auth **root, char *scope);
3434
struct uri_auth *stats_set_node(struct uri_auth **root, char *name);
3535
struct uri_auth *stats_set_desc(struct uri_auth **root, char *desc);
36+
void stats_uri_auth_free(struct uri_auth *uri_auth);
3637

3738
#endif /* _HAPROXY_URI_AUTH_H */
3839

src/haproxy.c

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3283,35 +3283,9 @@ void deinit(void)
32833283
proxy_destroy_all_unref_defaults();
32843284

32853285
while (ua) {
3286-
struct stat_scope *scope, *scopep;
3287-
struct stats_admin_rule *rule, *ruleb;
3288-
32893286
uap = ua;
32903287
ua = ua->next;
3291-
3292-
free(uap->uri_prefix);
3293-
free(uap->auth_realm);
3294-
free(uap->node);
3295-
free(uap->desc);
3296-
3297-
userlist_free(uap->userlist);
3298-
free_act_rules(&uap->http_req_rules);
3299-
list_for_each_entry_safe(rule, ruleb, &uap->admin_rules, list) {
3300-
LIST_DELETE(&rule->list);
3301-
free_acl_cond(rule->cond);
3302-
free(rule);
3303-
}
3304-
3305-
scope = uap->scope;
3306-
while (scope) {
3307-
scopep = scope;
3308-
scope = scope->next;
3309-
3310-
free(scopep->px_id);
3311-
free(scopep);
3312-
}
3313-
3314-
free(uap);
3288+
stats_uri_auth_free(uap);
33153289
}
33163290

33173291
userlist_free(userlist);

src/uri_auth.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
#include <stdlib.h>
1414
#include <string.h>
1515

16+
#include <haproxy/acl.h>
17+
#include <haproxy/action.h>
1618
#include <haproxy/api.h>
19+
#include <haproxy/auth.h>
1720
#include <haproxy/base64.h>
1821
#include <haproxy/errors.h>
1922
#include <haproxy/list.h>
@@ -310,6 +313,35 @@ struct uri_auth *stats_add_scope(struct uri_auth **root, char *scope)
310313
return NULL;
311314
}
312315

316+
void stats_uri_auth_free(struct uri_auth *uri_auth)
317+
{
318+
struct stat_scope *scope, *scopep;
319+
struct stats_admin_rule *rule, *ruleb;
320+
321+
free(uri_auth->uri_prefix);
322+
free(uri_auth->auth_realm);
323+
free(uri_auth->node);
324+
free(uri_auth->desc);
325+
326+
userlist_free(uri_auth->userlist);
327+
free_act_rules(&uri_auth->http_req_rules);
328+
list_for_each_entry_safe(rule, ruleb, &uri_auth->admin_rules, list) {
329+
LIST_DELETE(&rule->list);
330+
free_acl_cond(rule->cond);
331+
free(rule);
332+
}
333+
334+
scope = uri_auth->scope;
335+
while (scope) {
336+
scopep = scope;
337+
scope = scope->next;
338+
free(scopep->px_id);
339+
free(scopep);
340+
}
341+
342+
free(uri_auth);
343+
}
344+
313345
/*
314346
* Local variables:
315347
* c-indent-level: 8

0 commit comments

Comments
 (0)