From: Tim Duesterhus Date: Sat, 4 Jul 2020 09:49:41 +0000 (+0200) Subject: BUG/MINOR: haproxy: Add missing free of server->(hostname|resolvers_id) X-Git-Tag: v2.3-dev1~56 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb8f13c26db6a194dba94351ced4c2372ac61e02;p=thirdparty%2Fhaproxy.git BUG/MINOR: haproxy: Add missing free of server->(hostname|resolvers_id) 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. --- diff --git a/src/haproxy.c b/src/haproxy.c index 4b3800ae0c..862f68d5fa 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -2757,12 +2757,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)