]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: haproxy: Free srule->expr during deinit
authorTim Duesterhus <tim@bastelstu.be>
Sat, 4 Jul 2020 09:49:44 +0000 (11:49 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 7 Jul 2020 14:52:35 +0000 (16:52 +0200)
Given the following example configuration:

    backend foo
     mode http
     use-server %[str(x)] if { always_true }
     server x example.com:80

Running a configuration check with valgrind reports:

    ==19376== 170 (40 direct, 130 indirect) bytes in 1 blocks are definitely lost in loss record 281 of 347
    ==19376==    at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==19376==    by 0x5091AC: add_sample_to_logformat_list (log.c:511)
    ==19376==    by 0x50A5A6: parse_logformat_string (log.c:671)
    ==19376==    by 0x4957F2: check_config_validity (cfgparse.c:2588)
    ==19376==    by 0x54442D: init (haproxy.c:2129)
    ==19376==    by 0x421E42: main (haproxy.c:3169)

After this patch is applied 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

index 65067f24912cb4fe9e8649f08345220c1ee7e443..dafea44fdd532bad6edc68d6219fbf38b2579d11 100644 (file)
@@ -2666,6 +2666,12 @@ void deinit(void)
                list_for_each_entry_safe(srule, sruleb, &p->server_rules, list) {
                        LIST_DEL(&srule->list);
                        prune_acl_cond(srule->cond);
+                       list_for_each_entry_safe(lf, lfb, &srule->expr, list) {
+                               LIST_DEL(&lf->list);
+                               release_sample_expr(lf->expr);
+                               free(lf->arg);
+                               free(lf);
+                       }
                        free(srule->file);
                        free(srule->cond);
                        free(srule);