]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MINOR: logs: fix logsrv leaks on clean exit
authorWilly Tarreau <w@1wt.eu>
Thu, 17 Mar 2022 18:47:33 +0000 (19:47 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 17 Mar 2022 18:53:46 +0000 (19:53 +0100)
commit211ea252d9b6dba0bfc9ca24007ec60054bf75b8
treee3b2499bea5e5c1e796215f87b14454f8143741a
parent43c2ce4d81d8184007a8eb49240b81687c213dec
BUG/MINOR: logs: fix logsrv leaks on clean exit

Log servers are a real mess because:
  - entries are duplicated using memcpy() without their strings being
    reallocated, which results in these ones not being freeable every
    time.

  - a new field, ring_name, was added in 2.2 by commit 99c453df9
    ("MEDIUM: ring: new section ring to declare custom ring buffers.")
    but it's never initialized during copies, causing the same issue

  - no attempt is made at freeing all that.

Of course, running "haproxy -c" under ASAN quickly notices that and
dumps a core.

This patch adds the missing strdup() and initialization where required,
adds a new free_logsrv() function to cleanly free() such a structure,
calls it from the proxy when iterating over logsrvs instead of silently
leaking their file names and ring names, and adds the same logsrv loop
to the proxy_free_defaults() function so that we don't leak defaults
sections on exit.

It looks a bit entangled, but it comes as a whole because all this stuff
is inter-dependent and was missing.

It's probably preferable not to backport this in the foreseable future
as it may reveal other jokes if some obscure parts continue to memcpy()
the logsrv struct.
include/haproxy/log.h
src/http_client.c
src/log.c
src/proxy.c