From 116178563c2fb57e28a76838cf85c4858b185b76 Mon Sep 17 00:00:00 2001 From: Amaury Denoyelle Date: Tue, 22 Oct 2024 11:02:15 +0200 Subject: [PATCH] BUG/MINOR: server: fix dynamic server leak with check on failed init 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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/server.c b/src/server.c index b3900933d5..fdc7502128 100644 --- a/src/server.c +++ b/src/server.c @@ -5975,10 +5975,14 @@ static int cli_parse_add_server(char **args, char *payload, struct appctx *appct 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);