]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: sample: Memory leak of sample_expr structure in case of error
authorRemi Tricot-Le Breton <rlebreton@haproxy.com>
Tue, 12 Jan 2021 13:55:12 +0000 (14:55 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 12 Jan 2021 16:00:59 +0000 (17:00 +0100)
If an errors occurs during the sample expression parsing, the alloced
sample_expr is not freed despite having its main pointer reset.

This fixes GitHub issue #1046.
It could be backported as far as 1.8.

src/sample.c

index 7e4a0d06092dea73808b650560b7b550bda1e76b..bf2de2a2522ddd55fda61b6cc317cd25b5fbc533 100644 (file)
@@ -839,7 +839,7 @@ struct sample_expr *sample_parse_expr(char **str, int *idx, const char *file, in
        const char *begw; /* beginning of word */
        const char *endw; /* end of word */
        const char *endt; /* end of term */
-       struct sample_expr *expr;
+       struct sample_expr *expr = NULL;
        struct sample_fetch *fetch;
        struct sample_conv *conv;
        unsigned long prev_type;
@@ -1022,7 +1022,7 @@ struct sample_expr *sample_parse_expr(char **str, int *idx, const char *file, in
        return expr;
 
 out_error:
-       /* TODO: prune_sample_expr(expr); */
+       release_sample_expr(expr);
        expr = NULL;
        goto out;
 }