3 /* Copyright 1998 by the Massachusetts Institute of Technology.
5 * Permission to use, copy, modify, and distribute this
6 * software and its documentation for any purpose and without
7 * fee is hereby granted, provided that the above copyright
8 * notice appear in all copies and that both that copyright
9 * notice and this permission notice appear in supporting
10 * documentation, and that the name of M.I.T. not be used in
11 * advertising or publicity pertaining to distribution of the
12 * software without specific, written prior permission.
13 * M.I.T. makes no representations about the suitability of
14 * this software for any purpose. It is provided "as is"
15 * without express or implied warranty.
22 #include "ares_private.h"
24 void ares_destroy_options(struct ares_options *options)
28 free(options->servers);
29 for (i = 0; i < options->ndomains; i++)
30 free(options->domains[i]);
31 free(options->domains);
33 free(options->sortlist);
34 free(options->lookups);
37 void ares_destroy(ares_channel channel)
41 struct list_node* list_head;
42 struct list_node* list_node;
47 list_head = &(channel->all_queries);
48 for (list_node = list_head->next; list_node != list_head; )
50 query = list_node->data;
51 list_node = list_node->next; /* since we're deleting the query */
52 query->callback(query->arg, ARES_EDESTRUCTION, 0, NULL, 0);
53 ares__free_query(query);
56 /* Freeing the query should remove it from all the lists in which it sits,
57 * so all query lists should be empty now.
59 assert(ares__is_list_empty(&(channel->all_queries)));
60 for (i = 0; i < ARES_QID_TABLE_SIZE; i++)
62 assert(ares__is_list_empty(&(channel->queries_by_qid[i])));
64 for (i = 0; i < ARES_TIMEOUT_TABLE_SIZE; i++)
66 assert(ares__is_list_empty(&(channel->queries_by_timeout[i])));
70 if (channel->servers) {
71 for (i = 0; i < channel->nservers; i++)
73 struct server_state *server = &channel->servers[i];
74 ares__close_sockets(channel, server);
75 assert(ares__is_list_empty(&(server->queries_to_server)));
77 free(channel->servers);
80 if (channel->domains) {
81 for (i = 0; i < channel->ndomains; i++)
82 free(channel->domains[i]);
83 free(channel->domains);
87 free(channel->sortlist);
90 free(channel->lookups);