Skip to content

Commit c97ced3

Browse files
committed
BUG/MINOR: log: fix potential memory leak upon error in add_to_logformat_list()
As reported on GH haproxy#3099, upon memory error add_to_logformat_list() will return and error but it fails to properly memory which was allocated within the function, which could result in memory leak. Let's free all relevant variables allocated by the function before returning. No backport needed unless 22ac1f5 ("("BUG/MINOR: log: Add OOM checks for calloc() and malloc() in logformat parser and dup_logger()") is.
1 parent 842f32f commit c97ced3

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/log.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ int add_to_logformat_list(char *start, char *end, int type, struct lf_expr *lf_e
575575
struct logformat_node *node = calloc(1, sizeof(*node));
576576
str = calloc(1, end - start + 1);
577577
if (unlikely(!node || !str)) {
578+
free(node);
579+
free(str);
578580
memprintf(err, "out of memory error");
579581
return 0;
580582
}

0 commit comments

Comments
 (0)