Given the following example configuration:

    resolvers test
        nameserver test 127.0.0.1:53
    listen foo
        bind *:8080
        server foo example.com resolvers test

Running a configuration check within valgrind reports:

    ==21995== 5 bytes in 1 blocks are definitely lost in loss record 1 of 30
    ==21995==    at 0x4C2DB8F: malloc (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==21995==    by 0x5726489: strdup (strdup.c:42)
    ==21995==    by 0x4B2CFB: parse_server (server.c:2163)
    ==21995==    by 0x4680C1: cfg_parse_listen (cfgparse-listen.c:534)
    ==21995==    by 0x459E33: readcfgfile (cfgparse.c:2167)
    ==21995==    by 0x50778D: init (haproxy.c:2021)
    ==21995==    by 0x418262: main (haproxy.c:3133)
    ==21995==
    ==21995== 12 bytes in 1 blocks are definitely lost in loss record 3 of 30
    ==21995==    at 0x4C2DB8F: malloc (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==21995==    by 0x5726489: strdup (strdup.c:42)
    ==21995==    by 0x4AC666: srv_prepare_for_resolution (server.c:1606)
    ==21995==    by 0x4B2EBD: parse_server (server.c:2081)
    ==21995==    by 0x4680C1: cfg_parse_listen (cfgparse-listen.c:534)
    ==21995==    by 0x459E33: readcfgfile (cfgparse.c:2167)
    ==21995==    by 0x50778D: init (haproxy.c:2021)
    ==21995==    by 0x418262: main (haproxy.c:3133)

with one more leak unrelated to `struct server`. After applying this
patch the leak is gone as expected.

This is a very minor leak that can only be observed if deinit() is called,
shortly before the OS will free all memory of the process anyway. No
backport needed.
---
 src/haproxy.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/haproxy.c b/src/haproxy.c
index b5b426086..cbd9d3e67 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -2756,12 +2756,14 @@ void deinit(void)
 
                        free(s->id);
                        free(s->cookie);
+                       free(s->hostname);
                        free(s->hostname_dn);
                        free((char*)s->conf.file);
                        free(s->idle_conns);
                        free(s->safe_conns);
                        free(s->available_conns);
                        free(s->curr_idle_thr);
+                       free(s->resolvers_id);
 
                        if (s->use_ssl == 1 || s->check.use_ssl == 1 || 
(s->proxy->options & PR_O_TCPCHK_SSL)) {
                                if (xprt_get(XPRT_SSL) && 
xprt_get(XPRT_SSL)->destroy_srv)
-- 
2.27.0


Reply via email to