mirror of
https://github.com/haproxy/haproxy.git
synced 2026-05-28 04:12:17 -04:00
BUG/MINOR: tools: fix memory leak in indent_msg() on out of memory
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.
This commit is contained in:
parent
84cb8dd126
commit
d5efce7a13
1 changed files with 3 additions and 1 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue