]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: acl: Fix memory leaks when an ACL expression is parsed
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 13 Sep 2019 07:50:15 +0000 (09:50 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 13 Sep 2019 08:08:44 +0000 (10:08 +0200)
This only happens during the configuration parsing. First leak is the string
representing the last converter parsed, if any. The second one is on the error
path, when the allocation of the ACL expression failed. In this case, the sample
was not released.

This patch fixes the issue #256. It must be backported to all stable versions.

src/acl.c

index 318cb5139b11399de2d667723b1707deb9b06471..209580a11dfed0d1043529bc4e640a0c4aabdc60 100644 (file)
--- a/src/acl.c
+++ b/src/acl.c
@@ -342,6 +342,8 @@ struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *
                                goto out_free_smp;
                        }
                }
+               free(ckw);
+               ckw = NULL;
        }
        else {
                /* This is not an ACL keyword, so we hope this is a sample fetch
@@ -360,7 +362,7 @@ struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *
        expr = calloc(1, sizeof(*expr));
        if (!expr) {
                memprintf(err, "out of memory when parsing ACL expression");
-               goto out_return;
+               goto out_free_smp;
        }
 
        pattern_init_head(&expr->pat);
@@ -678,8 +680,8 @@ struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *
  out_free_expr:
        prune_acl_expr(expr);
        free(expr);
-       free(ckw);
  out_free_smp:
+       free(ckw);
        free(smp);
  out_return:
        return NULL;