]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MINOR: tools: add minimal file name management
authorWilly Tarreau <w@1wt.eu>
Thu, 19 Sep 2024 12:56:01 +0000 (14:56 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 19 Sep 2024 13:36:58 +0000 (15:36 +0200)
commitd6c060c5aec777c82d58341a47a991ef1a573116
treedecb2e00b21886254f8edd279dbecb44e7ccc02a
parent30a0e93fe68344d86557ba0ac8ad74325c646929
MINOR: tools: add minimal file name management

In proxies, stick-tables, servers, etc... at plenty of places we store
a file name and a line number. Some file names are the result of strdup()
(e.g. in proxies), others not (e.g. stick-tables) and leave dangling
pointers at the end of parsing. The risk of double-free is not null
either.

In order to stop this, let's first add a simple tool that allows to
register short strings inside a global list, these strings happening
to be server names. The strings are either duplicated and stored upon
failure to find them, or just added to this storage. Since file names
are not expected to disappear before the end of the process, for now
we don't even implement refcounting, and we free them all at the end.
There's already a drop_file_name() function to reset the pointer like
ha_free() used to do, and even if not strictly needed it's a good
habit to get used to doing it.

The strings are returned as const so that they're stored as-is in
structs, and that nasty free() calls are easily caught. The pointer
points to the char[] storage inside the node itself. This way later
if we want to implement refcounting, it will be trivial to just look
up a string and change its associated node's refcount. If needed,
comparisons can also be made on pointers.

For now they're not used yet and are released on deinit().
include/haproxy/tools-t.h
include/haproxy/tools.h
src/haproxy.c
src/tools.c