Hello all,
In several places in the source, there was the same block of code that was
used to deinitialize the log buffer. There were even two functions that
did this, but they were called only from the code that is in the same
source file (free_tcpcheck_fmt() in src/tcpcheck.c and free_logformat_list()
in src/proxy.c - they were both static functions).
The function free_logformat_list() was moved from the file src/proxy.c to
src/log.c, and a check of the list before freeing the memory was added to
that function.
Best regards,
--
Miroslav Zagorac
Senior DeveloperFrom 52ef575d77a47ef7338004fbad31d8199e59c752 Mon Sep 17 00:00:00 2001
From: Miroslav Zagorac
Date: Tue, 30 Jan 2024 03:14:09 +0100
Subject: [PATCH] CLEANUP: log: deinitialization of the log buffer in one
function
In several places in the source, there was the same block of code that was
used to deinitialize the log buffer. There were even two functions that
did this, but they were called only from the code that is in the same
source file (free_tcpcheck_fmt() in src/tcpcheck.c and free_logformat_list()
in src/proxy.c - they were both static functions).
The function free_logformat_list() was moved from the file src/proxy.c to
src/log.c, and a check of the list before freeing the memory was added to
that function.
---
include/haproxy/log.h | 3 +++
src/fcgi-app.c| 11 +--
src/http_act.c| 28
src/http_htx.c| 26 --
src/http_rules.c | 9 +
src/log.c | 16
src/proxy.c | 12
src/tcpcheck.c| 39 +--
src/vars.c| 9 +
9 files changed, 43 insertions(+), 110 deletions(-)
diff --git a/include/haproxy/log.h b/include/haproxy/log.h
index 68b820734..9534eaeb2 100644
--- a/include/haproxy/log.h
+++ b/include/haproxy/log.h
@@ -64,6 +64,9 @@ void syslog_fd_handler(int fd);
int init_log_buffers(void);
void deinit_log_buffers(void);
+/* Deinitialize log buffers used for syslog messages */
+void free_logformat_list(struct list *fmt);
+
/* build a log line for the session and an optional stream */
int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t maxsize, struct list *list_format);
diff --git a/src/fcgi-app.c b/src/fcgi-app.c
index 00562f80d..dcd7fd224 100644
--- a/src/fcgi-app.c
+++ b/src/fcgi-app.c
@@ -134,16 +134,7 @@ static void fcgi_release_rule(struct fcgi_rule *rule)
if (!rule)
return;
- if (!LIST_ISEMPTY(&rule->value)) {
- struct logformat_node *lf, *lfb;
-
- list_for_each_entry_safe(lf, lfb, &rule->value, list) {
- LIST_DELETE(&lf->list);
- release_sample_expr(lf->expr);
- free(lf->arg);
- free(lf);
- }
- }
+ free_logformat_list(&rule->value);
/* ->cond and ->name are not owned by the rule */
free(rule);
}
diff --git a/src/http_act.c b/src/http_act.c
index 260fe1d67..ebc2bcc68 100644
--- a/src/http_act.c
+++ b/src/http_act.c
@@ -46,17 +46,10 @@
*/
static void release_http_action(struct act_rule *rule)
{
- struct logformat_node *lf, *lfb;
-
istfree(&rule->arg.http.str);
if (rule->arg.http.re)
regex_free(rule->arg.http.re);
- list_for_each_entry_safe(lf, lfb, &rule->arg.http.fmt, list) {
- LIST_DELETE(&lf->list);
- release_sample_expr(lf->expr);
- free(lf->arg);
- free(lf);
- }
+ free_logformat_list(&rule->arg.http.fmt);
}
/* Release memory allocated by HTTP actions relying on an http reply. Concretly,
@@ -1901,23 +1894,10 @@ static enum act_return http_action_set_map(struct act_rule *rule, struct proxy *
/* Release memory allocated by an http map/acl action. */
static void release_http_map(struct act_rule *rule)
{
- struct logformat_node *lf, *lfb;
-
free(rule->arg.map.ref);
- list_for_each_entry_safe(lf, lfb, &rule->arg.map.key, list) {
- LIST_DELETE(&lf->list);
- release_sample_expr(lf->expr);
- free(lf->arg);
- free(lf);
- }
- if (rule->action == 1) {
- list_for_each_entry_safe(lf, lfb, &rule->arg.map.value, list) {
- LIST_DELETE(&lf->list);
- release_sample_expr(lf->expr);
- free(lf->arg);
- free(lf);
- }
- }
+ free_logformat_list(&rule->arg.map.key);
+ if (rule->action == 1)
+ free_logformat_list(&rule->arg.map.value);
}
/* Parse a "add-acl", "del-acl", "set-map" or "del-map" actions. It takes one or
diff --git a/src/http_htx.c b/src/http_htx.c
index 004d3439a..954473db3 100644
--- a/src/http_htx.c
+++ b/src/http_htx.c
@@ -1117,7 +1117,6 @@ int http_str_to_htx(struct buffer *buf, struct ist raw, char **errmsg)
void release_http_reply(struct http_reply *http_reply)
{
- struct logformat_node *lf, *lfb;
struct http_reply_hdr *hdr, *hdrb;
if (!http_reply)
@@ -1126,12 +1125,7 @@ void release_http_reply(struct http_reply *http_re