]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MEDIUM: lua: fix memory leaks with realloc() on non-glibc systems
authorWilly Tarreau <w@1wt.eu>
Fri, 22 Oct 2021 14:00:02 +0000 (16:00 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 22 Oct 2021 14:40:09 +0000 (16:40 +0200)
commita5efdff93c36f75345a2a18f18bffee9b602bc7b
tree8a801089d0cb967525a500a77272e801cb7f2573
parent46be7e92b424d4d55a63aacaaf736882560f6397
BUG/MEDIUM: lua: fix memory leaks with realloc() on non-glibc systems

In issue #1406, Lev Petrushchak reported a nasty memory leak on Alpine
since haproxy 2.4 when using Lua, that memory profiling didn't detect.
After inspecting the code and Lua's code, it appeared that Lua's default
allocator does an explicit free() on size zero, while since 2.4 commit
d36c7fa5e ("MINOR: lua: simplify hlua_alloc() to only rely on realloc()"),
haproxy only calls realloc(ptr,0) that performs a free() on glibc but not
on other systems as it's not required by POSIX...

This patch reinstalls the explicit test for nsize==0 to call free().

Thanks to Lev for the very documented report, and to Tim for the links
to a musl thread on the same subject that confirms the diagnostic.

This must be backported to 2.4.
src/hlua.c