From: Christopher Faulet Date: Wed, 10 Mar 2021 13:40:39 +0000 (+0100) Subject: MINOR: resolvers: Use a function to remove answers attached to a resolution X-Git-Tag: v2.3.7~9 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=656b42714a05e578c0480f1751a065d8e96f8f3a;p=haproxy-2.3.git MINOR: resolvers: Use a function to remove answers attached to a resolution 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 --- diff --git a/include/haproxy/dns.h b/include/haproxy/dns.h index 2b232f8..71ecc7a 100644 --- a/include/haproxy/dns.h +++ b/include/haproxy/dns.h @@ -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); diff --git a/src/dns.c b/src/dns.c index 9285a9b..ee1796b 100644 --- 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); }