]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: log: fix leak in add_sample_to_logformat_list() error path
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 13 May 2024 14:24:10 +0000 (16:24 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Mon, 13 May 2024 14:44:27 +0000 (16:44 +0200)
If add_sample_to_logformat_list() fails to allocate new logformat_node,
then we directly jump to error_free label to cleanup the node using
free_logformat_node() before returning an error.

However if the node failed to allocate, then the sample expression that
was allocated just before (not yet assigned) isn't released
(free_logformat_node() is a no-op when NULL is provided). Thus if expr
wasn't assigned to the node during early failure, then it must be manually
released.

This bug was introduced by 2462e5bcc ("BUG/MINOR: log: fix potential
lf->name memory leak") which wasn't marked for backports. It only
affects 3.0.

src/log.c

index 8cc48799673f6d883860280ea42de45a6a4781cd..5ae0ec0ea2bb611a65ee421667eba0e4a86c24a5 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -547,6 +547,7 @@ static int add_sample_to_logformat_list(char *text, char *name, int name_len, in
 
        node = calloc(1, sizeof(*node));
        if (!node) {
+               release_sample_expr(expr);
                memprintf(err, "out of memory error");
                goto error_free;
        }