From 1dec5c793474027ddffbfca3849e5ca4e9e51083 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 10 Mar 2021 14:40:39 +0100 Subject: [PATCH] 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. --- include/haproxy/resolvers.h | 1 + src/resolvers.c | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/haproxy/resolvers.h b/include/haproxy/resolvers.h index 7dc8819ca..34bc0fbf4 100644 --- a/include/haproxy/resolvers.h +++ b/include/haproxy/resolvers.h @@ -43,6 +43,7 @@ int resolv_get_ip_from_response(struct resolv_response *r_res, void **newip, short *newip_sin_family, void *owner); +void resolv_purge_resolution_answer_records(struct resolv_resolution *resolution); int resolv_link_resolution(void *requester, int requester_type, int requester_locked); void resolv_unlink_resolution(struct resolv_requester *requester); void resolv_trigger_resolution(struct resolv_requester *requester); diff --git a/src/resolvers.c b/src/resolvers.c index e2d410545..94cc101df 100644 --- a/src/resolvers.c +++ b/src/resolvers.c @@ -1683,11 +1683,21 @@ static struct resolv_resolution *resolv_pick_resolution(struct resolvers *resolv return res; } +void resolv_purge_resolution_answer_records(struct resolv_resolution *resolution) +{ + struct resolv_answer_item *item, *itemback; + + list_for_each_entry_safe(item, itemback, &resolution->response.answer_list, list) { + LIST_DEL(&item->list); + pool_free(resolv_answer_item_pool, item->ar_item); + pool_free(resolv_answer_item_pool, item); + } +} + /* Releases a resolution from its requester(s) and move it back to the pool */ static void resolv_free_resolution(struct resolv_resolution *resolution) { struct resolv_requester *req, *reqback; - struct resolv_answer_item *item, *itemback; /* clean up configuration */ resolv_reset_resolution(resolution); @@ -1698,16 +1708,7 @@ static void resolv_free_resolution(struct resolv_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(resolv_answer_item_pool, item->ar_item); - item->ar_item = NULL; - } - pool_free(resolv_answer_item_pool, item); - } - + resolv_purge_resolution_answer_records(resolution); LIST_DEL(&resolution->list); pool_free(resolv_resolution_pool, resolution); }