From b325453c36958249b4a3e9d8225b34db2a3047c4 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 19 Sep 2024 15:35:11 +0200 Subject: [PATCH] MINOR: proxy: use the global file names for conf->file Proxy file names are assigned a bit everywhere (resolvers, peers, cli, logs, proxy). All these elements were enumerated and now use copy_file_name(). The only ha_free() call was turned to drop_file_name(). As a bonus side effect, a 300k backend config saved 14 MB of RAM. --- include/haproxy/proxy-t.h | 2 +- src/cfgparse.c | 4 ++-- src/cli.c | 2 +- src/log.c | 2 +- src/proxy.c | 4 ++-- src/resolvers.c | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/haproxy/proxy-t.h b/include/haproxy/proxy-t.h index 74b4ab6d64..a1e01dd4e1 100644 --- a/include/haproxy/proxy-t.h +++ b/include/haproxy/proxy-t.h @@ -414,7 +414,7 @@ struct proxy { int no_options2; /* PR_O2_* */ struct { - char *file; /* file where the section appears */ + const char *file; /* file where the section appears */ struct eb32_node id; /* place in the tree of used IDs */ int line; /* line where the section appears */ struct eb_root used_listener_id;/* list of listener IDs in use */ diff --git a/src/cfgparse.c b/src/cfgparse.c index d90fdc5eab..27c1119c0c 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -574,8 +574,8 @@ static int init_peers_frontend(const char *file, int linenum, out: if (id && !p->id) p->id = strdup(id); - free(p->conf.file); - p->conf.args.file = p->conf.file = strdup(file); + drop_file_name(&p->conf.file); + p->conf.args.file = p->conf.file = copy_file_name(file); if (linenum != -1) p->conf.args.line = p->conf.line = linenum; diff --git a/src/cli.c b/src/cli.c index fafe6a34aa..5d8e7ae919 100644 --- a/src/cli.c +++ b/src/cli.c @@ -3293,7 +3293,7 @@ int mworker_cli_proxy_create() mworker_proxy->mode = PR_MODE_CLI; mworker_proxy->maxconn = 10; /* default to 10 concurrent connections */ mworker_proxy->timeout.client = 0; /* no timeout */ - mworker_proxy->conf.file = strdup("MASTER"); + mworker_proxy->conf.file = copy_file_name("MASTER"); mworker_proxy->conf.line = 0; mworker_proxy->accept = frontend_accept; mworker_proxy-> lbprm.algo = BE_LB_ALGO_NONE; diff --git a/src/log.c b/src/log.c index 8b6e9b61f7..883be829a7 100644 --- a/src/log.c +++ b/src/log.c @@ -5886,7 +5886,7 @@ int cfg_parse_log_forward(const char *file, int linenum, char **args, int kwm) init_new_proxy(px); px->next = cfg_log_forward; cfg_log_forward = px; - px->conf.file = strdup(file); + px->conf.file = copy_file_name(file); px->conf.line = linenum; px->mode = PR_MODE_SYSLOG; px->fe_counters.last_change = ns_to_sec(now_ns); diff --git a/src/proxy.c b/src/proxy.c index e719d86e23..a6e94f66cb 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -203,7 +203,7 @@ static inline void proxy_free_common(struct proxy *px) struct lf_expr *lf, *lfb; ha_free(&px->id); - ha_free(&px->conf.file); + drop_file_name(&px->conf.file); ha_free(&px->check_command); ha_free(&px->check_path); ha_free(&px->cookie_name); @@ -1850,7 +1850,7 @@ struct proxy *parse_new_proxy(const char *name, unsigned int cap, } } - curproxy->conf.args.file = curproxy->conf.file = strdup(file); + curproxy->conf.args.file = curproxy->conf.file = copy_file_name(file); curproxy->conf.args.line = curproxy->conf.line = linenum; return curproxy; diff --git a/src/resolvers.c b/src/resolvers.c index 99b4ef0cf5..9e28bf6867 100644 --- a/src/resolvers.c +++ b/src/resolvers.c @@ -3496,7 +3496,7 @@ static int resolvers_new(struct resolvers **resolvers, const char *id, const cha resolvers_setup_proxy(p); p->parent = r; p->id = strdup(id); - p->conf.args.file = p->conf.file = strdup(file); + p->conf.args.file = p->conf.file = copy_file_name(file); p->conf.args.line = p->conf.line = linenum; r->px = p; -- 2.39.5