From: Willy Tarreau Date: Mon, 7 Jul 2025 14:57:24 +0000 (+0200) Subject: MINOR: resolvers: do not duplicate the hostname_dn field X-Git-Tag: v3.3-dev3~21 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=96da670cd71cc2f6b41f87d4fc22f9517789b6da;p=thirdparty%2Fhaproxy.git MINOR: resolvers: do not duplicate the hostname_dn field The hostdn.key field in the server contains a pure copy of the hostname_dn since commit 3406766d57 ("MEDIUM: resolvers: add a ref between servers and srv request or used SRV record") which wanted to lowercase it. Since it's not necessary, let's drop this useless copy. In addition, the return from strdup() was not tested, so it could theoretically crash the process under heavy memory contention. --- diff --git a/src/resolvers.c b/src/resolvers.c index cafae8e2b..c788cd437 100644 --- a/src/resolvers.c +++ b/src/resolvers.c @@ -741,6 +741,10 @@ static void resolv_srvrq_cleanup_srv(struct server *srv) _resolv_unlink_resolution(srv->resolv_requester); HA_SPIN_LOCK(SERVER_LOCK, &srv->lock); srvrq_set_srv_down(srv); + + ebpt_delete(&srv->host_dn); + srv->host_dn.key = NULL; + ha_free(&srv->hostname); ha_free(&srv->hostname_dn); srv->hostname_dn_len = 0; @@ -749,9 +753,6 @@ static void resolv_srvrq_cleanup_srv(struct server *srv) server_set_inetaddr(srv, &srv_addr, SERVER_INETADDR_UPDATER_NONE, NULL); srv->flags |= SRV_F_NO_RESOLUTION; - ebpt_delete(&srv->host_dn); - ha_free(&srv->host_dn.key); - HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock); LIST_DEL_INIT(&srv->srv_rec_item); LIST_APPEND(&srv->srvrq->attached_servers, &srv->srv_rec_item); @@ -873,7 +874,7 @@ static void resolv_check_response(struct resolv_resolution *res) if (srv->svc_port == item->port) { /* server found, we remove it from tree */ ebpt_delete(node); - ha_free(&srv->host_dn.key); + srv->host_dn.key = NULL; goto srv_found; } diff --git a/src/server_state.c b/src/server_state.c index 21170f8d2..1d38f068b 100644 --- a/src/server_state.c +++ b/src/server_state.c @@ -415,7 +415,7 @@ static void srv_state_srv_update(struct server *srv, int version, char **params) * since this server has an hostname */ LIST_DEL_INIT(&srv->srv_rec_item); - srv->host_dn.key = strdup(srv->hostname_dn); + srv->host_dn.key = srv->hostname_dn; /* insert in tree and set the srvrq expiration date */ ebis_insert(&srv->srvrq->named_servers, &srv->host_dn);