]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: server: fix dynamic server leak with check on failed init
authorAmaury Denoyelle <adenoyelle@haproxy.com>
Tue, 22 Oct 2024 09:02:15 +0000 (11:02 +0200)
committerAmaury Denoyelle <adenoyelle@haproxy.com>
Thu, 24 Oct 2024 09:35:57 +0000 (11:35 +0200)
If a dynamic server is added with check or agent-check, its refcount is
incremented after server keyword parsing. However, if add server fails
at a later stage, refcount is only decremented once, which prevented the
server to be fully released.

This causes a leak with a server which is detached from most of the
lists but still exits in the system.

This bug is considered minor as only a few conditions may cause a
failure in add server after check/agent-check initialization. This is
the case if there is a naming collision or the dynamic ID cannot be
generated.

To fix this, simply decrement server refcount on add server error path
if either check and/or agent-check are flagged as activated.

This bug is related to github issue #2733. Thanks to Chris Staite who
first found the leak.

This must be backported up to 2.6.

src/server.c

index b3900933d58520097aeb3431ac0d38f0bdb26d44..fdc750212858cfb5eefdd3fe7ef1cad0e1d0bfc3 100644 (file)
@@ -5975,10 +5975,14 @@ out:
                if (srv->track)
                        release_server_track(srv);
 
-               if (srv->check.state & CHK_ST_CONFIGURED)
+               if (srv->check.state & CHK_ST_CONFIGURED) {
                        free_check(&srv->check);
-               if (srv->agent.state & CHK_ST_CONFIGURED)
+                       srv_drop(srv);
+               }
+               if (srv->agent.state & CHK_ST_CONFIGURED) {
                        free_check(&srv->agent);
+                       srv_drop(srv);
+               }
 
                /* remove the server from the proxy linked list */
                _srv_detach(srv);