]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: check: fix leak on add dynamic server with agent-check error
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 10 Aug 2021 14:22:51 +0000 (16:22 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Wed, 11 Aug 2021 12:37:42 +0000 (14:37 +0200)
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

index 8ad32fe8f81b99034f9c455407e20d32fade32ff..6225cc8feb6f664e4040150f80cbf82156b4274b 100644 (file)
@@ -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);