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.
This commit is contained in:
Christopher Faulet 2021-03-10 14:40:39 +01:00
parent 3e0600fbbf
commit 1dec5c7934
2 changed files with 13 additions and 11 deletions

View File

@ -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);

View File

@ -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);
}