]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: server: introduce srv_alloc()/srv_free() to alloc/free a server
authorWilly Tarreau <w@1wt.eu>
Wed, 13 Aug 2025 09:52:59 +0000 (11:52 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 13 Aug 2025 15:37:11 +0000 (17:37 +0200)
commita469356268f463d24b9d0e71e0cfa5826ac02a5c
tree72a08273c7ded32ceba8b6a6a51be11be61a4b5c
parent33d72568dd40fb3c3344ab4273e5e8f10ac73774
MEDIUM: server: introduce srv_alloc()/srv_free() to alloc/free a server

It happens that we free servers at various places in the code, both
on error paths and at runtime thanks to the "server delete" feature. In
order to switch to an aligned struct, we'll need to change the calloc()
and free() calls. Let's first spot them and switch them to srv_alloc()
and srv_free() instead of using calloc() and either free() or ha_free().
An easy trap to fall into is that some of them are default-server
entries. The new srv_free() function also resets the pointer like
ha_free() does.

This was done by running the following coccinelle script all over the
code:

  @@
  struct server *srv;
  @@
  (
  - free(srv)
  + srv_free(&srv)
  |
  - ha_free(&srv)
  + srv_free(&srv)
  )
  @@
  struct server *srv;
  expression e1;
  expression e2;
  @@
  (
  - srv = malloc(e1)
  + srv = srv_alloc()
  |
  - srv = calloc(e1, e2)
  + srv = srv_alloc()
  )

This is marked medium because despite spotting all call places, we can
never rule out the possibility that some out-of-tree patches would
allocate their own servers and continue to use the old API... at their
own risk.
include/haproxy/server.h
src/cli.c
src/proxy.c
src/server.c