MINOR: resolvers: Use a function to remove answers attached to a resolution
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 10 Mar 2021 13:40:39 +0000 (14:40 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 16 Mar 2021 08:33:53 +0000 (09:33 +0100)
resolv_purge_resolution_answer_records() must be used to removed all answers
attached to a resolution. For now, it is only used when a resolution is
released.

(cherry picked from commit 1dec5c793474027ddffbfca3849e5ca4e9e51083)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

include/haproxy/dns.h
src/dns.c

index 2b232f8..71ecc7a 100644 (file)
@@ -43,6 +43,7 @@ int dns_get_ip_from_response(struct dns_response_packet *dns_p,
                              void **newip, short *newip_sin_family,
                              void *owner);
 
+void dns_purge_resolution_answer_records(struct dns_resolution *resolution);
 int dns_link_resolution(void *requester, int requester_type, int requester_locked);
 void dns_unlink_resolution(struct dns_requester *requester);
 void dns_trigger_resolution(struct dns_requester *requester);
index 9285a9b..ee1796b 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -1733,11 +1733,21 @@ static struct dns_resolution *dns_pick_resolution(struct dns_resolvers *resolver
        return res;
 }
 
+void dns_purge_resolution_answer_records(struct dns_resolution *resolution)
+{
+       struct dns_answer_item *item, *itemback;
+
+       list_for_each_entry_safe(item, itemback, &resolution->response.answer_list, list) {
+               LIST_DEL(&item->list);
+               pool_free(dns_answer_item_pool, item->ar_item);
+               pool_free(dns_answer_item_pool, item);
+       }
+}
+
 /* Releases a resolution from its requester(s) and move it back to the pool */
 static void dns_free_resolution(struct dns_resolution *resolution)
 {
        struct dns_requester *req, *reqback;
-       struct dns_answer_item *item, *itemback;
 
        /* clean up configuration */
        dns_reset_resolution(resolution);
@@ -1748,16 +1758,7 @@ static void dns_free_resolution(struct dns_resolution *resolution)
                LIST_DEL(&req->list);
                req->resolution = NULL;
        }
-
-       list_for_each_entry_safe(item, itemback, &resolution->response.answer_list, list) {
-               LIST_DEL(&item->list);
-               if (item->ar_item) {
-                       pool_free(dns_answer_item_pool, item->ar_item);
-                       item->ar_item = NULL;
-               }
-               pool_free(dns_answer_item_pool, item);
-       }
-
+       dns_purge_resolution_answer_records(resolution);
        LIST_DEL(&resolution->list);
        pool_free(dns_resolution_pool, resolution);
 }