From 55078fc88ea237b02ad2033489d29dd2ce3cac08 Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Thu, 4 Sep 2025 10:26:37 +0200 Subject: [PATCH] BUG/MINOR: log: fix potential memory leak upon error in add_to_logformat_list() As reported on GH #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 22ac1f5ee ("("BUG/MINOR: log: Add OOM checks for calloc() and malloc() in logformat parser and dup_logger()") is. (cherry picked from commit c97ced3f938271c9d648594d6c4bfcd194c36a7d) Signed-off-by: Christopher Faulet (cherry picked from commit 5d0cd28ce889a85fb4ef8d1617f8f61abd1ebea7) Signed-off-by: Christopher Faulet (cherry picked from commit 9ac6454aa1ebcb813f61f7b4fb6ac07dbb21d7ec) Signed-off-by: Christopher Faulet --- src/log.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/log.c b/src/log.c index 3c50379..90eabb2 100644 --- a/src/log.c +++ b/src/log.c @@ -496,6 +496,8 @@ int add_to_logformat_list(char *start, char *end, int type, struct lf_expr *lf_e struct logformat_node *node = calloc(1, sizeof(*node)); str = calloc(1, end - start + 1); if (unlikely(!node || !str)) { + free(node); + free(str); memprintf(err, "out of memory error"); return 0; } -- 1.7.10.4