]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: tools: fix memory leak in indent_msg() on out of memory
authorWilly Tarreau <w@1wt.eu>
Sun, 26 Apr 2026 21:00:57 +0000 (23:00 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 27 Apr 2026 12:44:29 +0000 (14:44 +0200)
When malloc() fails in indent_msg, the function returned NULL without
freeing the original *out string as it was supposed to. The caller loses
both the original string (leaked) and gets NULL back. Fixed to free *out
and set it to NULL before returning.

src/tools.c

index 7a48969ec41ad176b3196b686d3008f7209e6bc1..cdd9cbe5fcb8c1dbaf1c43bef4cd69dbbb76f051 100644 (file)
@@ -4744,7 +4744,8 @@ char *indent_msg(char **out, int level)
        needed = 1 + level * (lf + 1) + len + 1;
        p = ret = malloc(needed);
        if (unlikely(!ret))
-               return NULL;
+               goto leave;
+
        in = *out;
 
        /* skip initial LFs */
@@ -4764,6 +4765,7 @@ char *indent_msg(char **out, int level)
        }
        *p = 0;
 
+ leave:
        free(*out);
        *out = ret;