]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: vars: Fix memory leak in vars_check_arg
authorTim Duesterhus <tim@bastelstu.be>
Fri, 10 May 2019 15:50:50 +0000 (17:50 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 11 May 2019 04:00:50 +0000 (06:00 +0200)
vars_check_arg previously leaked the string containing the variable
name:

Consider this config:

    frontend fe1
        mode http
        bind :8080
        http-request set-header X %[var(txn.host)]

Starting HAProxy and immediately stopping it by sending a SIGINT makes
Valgrind report this leak:

    ==7795== 9 bytes in 1 blocks are definitely lost in loss record 15 of 71
    ==7795==    at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==7795==    by 0x4AA2AD: my_strndup (standard.c:2227)
    ==7795==    by 0x51FCC5: make_arg_list (arg.c:146)
    ==7795==    by 0x4CF095: sample_parse_expr (sample.c:897)
    ==7795==    by 0x4BA7D7: add_sample_to_logformat_list (log.c:495)
    ==7795==    by 0x4BBB62: parse_logformat_string (log.c:688)
    ==7795==    by 0x4E70A9: parse_http_req_cond (http_rules.c:239)
    ==7795==    by 0x41CD7B: cfg_parse_listen (cfgparse-listen.c:1466)
    ==7795==    by 0x480383: readcfgfile (cfgparse.c:2089)
    ==7795==    by 0x47A081: init (haproxy.c:1581)
    ==7795==    by 0x4049F2: main (haproxy.c:2591)

This leak can be detected even in HAProxy 1.6, this patch thus should
be backported to all supported branches.

src/vars.c

index 477a146328701c37a76c2d63ba26b483bf7e0a4c..aa8bf185d90bf5f5e78a29033eb785a265e78724 100644 (file)
@@ -510,6 +510,8 @@ int vars_check_arg(struct arg *arg, char **err)
                             err);
        if (!name)
                return 0;
+       free(arg->data.str.area);
+       arg->data.str.area = NULL;
 
        /* Use the global variable name pointer. */
        arg->type = ARGT_VAR;