From: Baptiste Assmann Date: Mon, 21 Jan 2019 07:18:09 +0000 (+0100) Subject: MINOR: dns: dns_requester structures are now in a memory pool X-Git-Tag: v2.0-dev3~196 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dfd35fd71ad9190a3d1f3c8358f335053b9834d8;p=thirdparty%2Fhaproxy.git MINOR: dns: dns_requester structures are now in a memory pool dns_requester structure can be allocated at run time when servers get associated to DNS resolution (this happens when SRV records are used in conjunction with service discovery). Well, this memory allocation is safer if managed in an HAProxy pool, furthermore with upcoming HTTP action which can perform DNS resolution at runtime. This patch moves the memory management of the dns_requester structure into its own pool. --- diff --git a/include/types/dns.h b/include/types/dns.h index 3d022d49ba..81cd6d2601 100644 --- a/include/types/dns.h +++ b/include/types/dns.h @@ -34,6 +34,8 @@ #include #include +extern struct pool_head *dns_requester_pool; + /*DNS maximum values */ /* * Maximum issued from RFC: diff --git a/src/dns.c b/src/dns.c index 274fa83b9a..46e35ef0a0 100644 --- a/src/dns.c +++ b/src/dns.c @@ -51,6 +51,7 @@ static THREAD_LOCAL int64_t dns_query_id_seed = 0; /* random seed */ DECLARE_STATIC_POOL(dns_answer_item_pool, "dns_answer_item", sizeof(struct dns_answer_item)); DECLARE_STATIC_POOL(dns_resolution_pool, "dns_resolution", sizeof(struct dns_resolution)); +DECLARE_POOL(dns_requester_pool, "dns_requester", sizeof(struct dns_requester)); static unsigned int resolution_uuid = 1; @@ -1384,7 +1385,7 @@ int dns_link_resolution(void *requester, int requester_type, int requester_locke if (!requester_locked) HA_SPIN_LOCK(SERVER_LOCK, &srv->lock); if (srv->dns_requester == NULL) { - if ((req = calloc(1, sizeof(*req))) == NULL) { + if ((req = pool_alloc(dns_requester_pool)) == NULL) { if (!requester_locked) HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock); goto err; @@ -1399,7 +1400,7 @@ int dns_link_resolution(void *requester, int requester_type, int requester_locke } else if (srvrq) { if (srvrq->dns_requester == NULL) { - if ((req = calloc(1, sizeof(*req))) == NULL) + if ((req = pool_alloc(dns_requester_pool)) == NULL) goto err; req->owner = &srvrq->obj_type; srvrq->dns_requester = req; @@ -1826,7 +1827,7 @@ static void dns_deinit(void) list_for_each_entry_safe(res, resback, &resolvers->resolutions.curr, list) { list_for_each_entry_safe(req, reqback, &res->requesters, list) { LIST_DEL(&req->list); - free(req); + pool_free(dns_requester_pool, req); } dns_free_resolution(res); } @@ -1834,7 +1835,7 @@ static void dns_deinit(void) list_for_each_entry_safe(res, resback, &resolvers->resolutions.wait, list) { list_for_each_entry_safe(req, reqback, &res->requesters, list) { LIST_DEL(&req->list); - free(req); + pool_free(dns_requester_pool, req); } dns_free_resolution(res); }