From 6d7fc446b47f1c51819ac519a1a1e52fdde6842b Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Tue, 10 Aug 2021 16:22:51 +0200 Subject: [PATCH] BUG/MINOR: check: fix leak on add dynamic server with agent-check error If an error occured during a dynamic server creation, free_check is used to liberate a possible agent-check. However, this does not free associated vars and rules associated as this is done on another function named deinit_srv_agent_check. To simplify the check free and avoid a leak, move free vars/rules in free_check. This is valid because deinit_srv_agent_check also uses free_check. This operation is done only for an agent-check because for a health check, the proxy instance is the owner of check vars/rules. This should not be backported, unless dynamic server checks are backported. --- src/check.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/check.c b/src/check.c index 8ad32fe8f..6225cc8fe 100644 --- a/src/check.c +++ b/src/check.c @@ -1337,11 +1337,19 @@ const char *init_check(struct check *check, int type) /* Liberates the resources allocated for a check. * - * This function must only be used at startup when it is known that the check - * has never been executed. + * This function must only be run by the thread owning the check. */ void free_check(struct check *check) { + /* For agent-check, free the rules / vars from the server. This is not + * done for health-check : the proxy is the owner of the rules / vars + * in this case. + */ + if (check->state & CHK_ST_AGENT) { + free_tcpcheck_vars(&check->tcpcheck_rules->preset_vars); + ha_free(&check->tcpcheck_rules); + } + task_destroy(check->task); if (check->wait_list.tasklet) tasklet_free(check->wait_list.tasklet); @@ -1763,11 +1771,6 @@ static void deinit_srv_check(struct server *srv) static void deinit_srv_agent_check(struct server *srv) { - if (srv->agent.tcpcheck_rules) { - free_tcpcheck_vars(&srv->agent.tcpcheck_rules->preset_vars); - ha_free(&srv->agent.tcpcheck_rules); - } - if (srv->agent.state & CHK_ST_CONFIGURED) free_check(&srv->agent);