]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: dns: dns_requester structures are now in a memory pool
authorBaptiste Assmann <bedis9@gmail.com>
Mon, 21 Jan 2019 07:18:09 +0000 (08:18 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 23 Apr 2019 09:33:48 +0000 (11:33 +0200)
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.

include/types/dns.h
src/dns.c

index 3d022d49ba78f2c875619d2089a90deec092670f..81cd6d260130273b0063bd69bbbb1533f523c451 100644 (file)
@@ -34,6 +34,8 @@
 #include <types/server.h>
 #include <types/task.h>
 
+extern struct pool_head *dns_requester_pool;
+
 /*DNS maximum values */
 /*
  * Maximum issued from RFC:
index 274fa83b9acea1c4a4acff4a782eb280b52c6a99..46e35ef0a089fc158f113f97e975e08f81683d28 100644 (file)
--- 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);
                }