]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: resolvers: Fix memory leak in resolvers_deinit()
authorTim Duesterhus <tim@bastelstu.be>
Tue, 26 Apr 2022 21:28:47 +0000 (23:28 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 26 Apr 2022 21:42:10 +0000 (23:42 +0200)
A config like the following:

    global
     stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners

    resolvers unbound
     nameserver unbound 127.0.0.1:53

will report the following leak when running a configuration check:

    ==241882== 6,991 (6,952 direct, 39 indirect) bytes in 1 blocks are definitely lost in loss record 8 of 13
    ==241882==    at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==241882==    by 0x25938D: cfg_parse_resolvers (resolvers.c:3193)
    ==241882==    by 0x26A1E8: readcfgfile (cfgparse.c:2171)
    ==241882==    by 0x156D72: init (haproxy.c:2016)
    ==241882==    by 0x156D72: main (haproxy.c:3037)

because the `.px` member of `struct resolvers` is not freed.

The offending allocation was introduced in
c943799c865c04281454a7a54fd6c45c2b4d7e09 which is a reorganization that
happened during development of 2.4.x. This fix can likely be backported without
issue to 2.4+ and is likely not needed for earlier versions as the leak happens
during deinit only.

src/resolvers.c

index 0b7faf93d64ccc3b578e4176e29e841503865d5c..3179073b55e504dcd47d97c91479daee26d58d88 100644 (file)
@@ -2448,6 +2448,7 @@ static void resolvers_deinit(void)
                        abort_resolution(res);
                }
 
+               free_proxy(resolvers->px);
                free(resolvers->id);
                free((char *)resolvers->conf.file);
                task_destroy(resolvers->t);