]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: server: do not leak default-server in defaults sections
authorWilly Tarreau <w@1wt.eu>
Thu, 23 Nov 2023 13:28:14 +0000 (14:28 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 23 Nov 2023 13:32:55 +0000 (14:32 +0100)
When a default-server directive is used in a defaults section, it's never
freed and the "defaults" proxy gets reset without freeing the fields from
that default-server. Normally there are no allocation there, except for
the config file location stored in srv->conf.file form an strdup() since
commit 9394a9444 ("REORG: server: move alert traces in parse_server")
that appeared in 2.4. In addition, if a "default-server" directive
appears multiple times in a defaults section, one more entry will be
leaked per call.

This commit addresses this by checking that we don't overwrite the file
upon multiple calls, and by clearing it when resetting the default proxy.
This should be backported to 2.4.

src/proxy.c
src/server.c

index 0bac0898f1dce8ef944a1d7e5d603d473c2e5080..3e126378f530a676ad25fa3beb0c64f0a76d02a3 100644 (file)
@@ -1517,6 +1517,7 @@ void proxy_free_defaults(struct proxy *defproxy)
 
        ha_free(&defproxy->id);
        ha_free(&defproxy->conf.file);
+       ha_free((char **)&defproxy->defsrv.conf.file);
        ha_free(&defproxy->check_command);
        ha_free(&defproxy->check_path);
        ha_free(&defproxy->cookie_name);
index 138d692729a9e74a76a02f5d34b26613e2429ca9..78c3b532dc406caf3d417dd43f4bb14f41c466bf 100644 (file)
@@ -3292,7 +3292,8 @@ int parse_server(const char *file, int linenum, char **args,
        if (err_code & ERR_CODE)
                goto out;
 
-       newsrv->conf.file = strdup(file);
+       if (!newsrv->conf.file) // note: do it only once for default-server
+               newsrv->conf.file = strdup(file);
        newsrv->conf.line = linenum;
 
        while (*args[cur_arg]) {