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)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 24 Oct 2024 10:10:01 +0000 (12:10 +0200)
commit55fada172ccc5cafdb87b627c407ad1ace96603e
treeda9814a728768426a93827c295364c6a1549e303
parentfcaae8d6d2c9fea545b1fdf9c45e62688ace2fb2
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.

(cherry picked from commit 116178563c2fb57e28a76838cf85c4858b185b76)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
src/server.c