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.
This commit is contained in:
Willy Tarreau 2025-07-07 16:57:24 +02:00
parent 95cf518bfa
commit 96da670cd7
2 changed files with 6 additions and 5 deletions

View File

@ -741,6 +741,10 @@ static void resolv_srvrq_cleanup_srv(struct server *srv)
_resolv_unlink_resolution(srv->resolv_requester); _resolv_unlink_resolution(srv->resolv_requester);
HA_SPIN_LOCK(SERVER_LOCK, &srv->lock); HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
srvrq_set_srv_down(srv); srvrq_set_srv_down(srv);
ebpt_delete(&srv->host_dn);
srv->host_dn.key = NULL;
ha_free(&srv->hostname); ha_free(&srv->hostname);
ha_free(&srv->hostname_dn); ha_free(&srv->hostname_dn);
srv->hostname_dn_len = 0; 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); server_set_inetaddr(srv, &srv_addr, SERVER_INETADDR_UPDATER_NONE, NULL);
srv->flags |= SRV_F_NO_RESOLUTION; srv->flags |= SRV_F_NO_RESOLUTION;
ebpt_delete(&srv->host_dn);
ha_free(&srv->host_dn.key);
HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock); HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
LIST_DEL_INIT(&srv->srv_rec_item); LIST_DEL_INIT(&srv->srv_rec_item);
LIST_APPEND(&srv->srvrq->attached_servers, &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) { if (srv->svc_port == item->port) {
/* server found, we remove it from tree */ /* server found, we remove it from tree */
ebpt_delete(node); ebpt_delete(node);
ha_free(&srv->host_dn.key); srv->host_dn.key = NULL;
goto srv_found; goto srv_found;
} }

View File

@ -415,7 +415,7 @@ static void srv_state_srv_update(struct server *srv, int version, char **params)
* since this server has an hostname * since this server has an hostname
*/ */
LIST_DEL_INIT(&srv->srv_rec_item); 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 */ /* insert in tree and set the srvrq expiration date */
ebis_insert(&srv->srvrq->named_servers, &srv->host_dn); ebis_insert(&srv->srvrq->named_servers, &srv->host_dn);