ares 1.1.1 with collected applied patches
[platform/upstream/c-ares.git] / ares_destroy.c
1 /* Copyright 1998 by the Massachusetts Institute of Technology.
2  *
3  * Permission to use, copy, modify, and distribute this
4  * software and its documentation for any purpose and without
5  * fee is hereby granted, provided that the above copyright
6  * notice appear in all copies and that both that copyright
7  * notice and this permission notice appear in supporting
8  * documentation, and that the name of M.I.T. not be used in
9  * advertising or publicity pertaining to distribution of the
10  * software without specific, written prior permission.
11  * M.I.T. makes no representations about the suitability of
12  * this software for any purpose.  It is provided "as is"
13  * without express or implied warranty.
14  */
15
16 static const char rcsid[] = "$Id$";
17
18 #include <stdlib.h>
19 #include "ares.h"
20 #include "ares_private.h"
21
22 void ares_destroy(ares_channel channel)
23 {
24   int i;
25   struct query *query;
26
27   for (i = 0; i < channel->nservers; i++)
28     ares__close_sockets(&channel->servers[i]);
29   free(channel->servers);
30   for (i = 0; i < channel->ndomains; i++)
31     free(channel->domains[i]);
32   free(channel->domains);
33   free(channel->sortlist);
34   free(channel->lookups);
35   while (channel->queries)
36     {
37       query = channel->queries;
38       channel->queries = query->next;
39       query->callback(query->arg, ARES_EDESTRUCTION, NULL, 0);
40       free(query->tcpbuf);
41       free(query->skip_server);
42       free(query);
43     }
44   free(channel);
45 }