From: Amaury Denoyelle Date: Wed, 22 Jul 2026 08:14:35 +0000 (+0200) Subject: MINOR: server: do not return next server on srv_drop() X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=257e2eefc95499099d9447b9c92fe3ea439c5e08;p=thirdparty%2Fhaproxy.git MINOR: server: do not return next server on srv_drop() Previously, srv_drop() returned the next server entry in the parent proxy. This was used as convenience during server iteration. However, the code has evolved several times to better deal with the server deletion risk. Currently, srv_drop() return value is only used in a single place. Thus, this patch simplifies srv_drop() by removing its return value. As a side effect, this will also reduce the modification required to convert the proxy server list to a doubly linked struct list. --- diff --git a/include/haproxy/server.h b/include/haproxy/server.h index 5662666a7..6d47cb343 100644 --- a/include/haproxy/server.h +++ b/include/haproxy/server.h @@ -79,7 +79,7 @@ int srv_init_addr(void); struct server *cli_find_server(struct appctx *appctx, char *arg); struct server *new_server(struct proxy *proxy); void srv_take(struct server *srv); -struct server *srv_drop(struct server *srv); +void srv_drop(struct server *srv); void srv_free_params(struct server *srv); int srv_preinit(struct server *srv); int srv_set_ssl(struct server *s, int use_ssl); diff --git a/src/proxy.c b/src/proxy.c index 7a87d79de..a1906f252 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -326,7 +326,7 @@ static inline void proxy_free_common(struct proxy *px) */ void deinit_proxy(struct proxy *p) { - struct server *s; + struct server *s, *s_next; struct cap_hdr *h,*h_next; struct listener *l,*l_next; struct bind_conf *bind_conf, *bind_back; @@ -414,7 +414,9 @@ void deinit_proxy(struct proxy *p) if (p->lbprm.ops && p->lbprm.ops->server_deinit) p->lbprm.ops->server_deinit(s); - s = srv_drop(s); + s_next = s->next; + srv_drop(s); + s = s_next; }/* end while(s) */ /* also free default-server parameters since some of them might have diff --git a/src/server.c b/src/server.c index 1dc5e1001..94a8e9772 100644 --- a/src/server.c +++ b/src/server.c @@ -3260,20 +3260,14 @@ void srv_free_params(struct server *srv) * * A general rule is to assume that proxy may already be freed, so cleanup checks * must not depend on the proxy - * - * As a convenience, is returned if srv is not NULL. It may be useful - * when calling srv_drop on the list of servers. */ -struct server *srv_drop(struct server *srv) +void srv_drop(struct server *srv) { - struct server *next = NULL; struct proxy *px = NULL; int i __maybe_unused; if (!srv) - goto end; - - next = srv->next; + return; /* If srv was deleted, a proxy refcount must be dropped. */ if (srv->flags & SRV_F_DELETED) @@ -3283,7 +3277,7 @@ struct server *srv_drop(struct server *srv) * server when reaching zero. */ if (HA_ATOMIC_SUB_FETCH(&srv->refcount, 1)) - goto end; + return; /* This BUG_ON() is invalid for now as server released on deinit will * trigger it as they are not properly removed from their tree. @@ -3322,9 +3316,6 @@ struct server *srv_drop(struct server *srv) srv_free(&srv); proxy_drop(px); - - end: - return next; } /* Remove a server from a tracking list if is tracking another