ares_destroy.c
Go to the documentation of this file.
1 
2 /* Copyright 1998 by the Massachusetts Institute of Technology.
3  * Copyright (C) 2004-2011 by Daniel Stenberg
4  *
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.
16  */
17 
18 #include "ares_setup.h"
19 
20 #include <assert.h>
21 
22 #include "ares.h"
23 #include "ares_private.h"
24 
26 {
27  int i;
28 
29  if(options->servers)
30  ares_free(options->servers);
31  for (i = 0; i < options->ndomains; i++)
32  ares_free(options->domains[i]);
33  if(options->domains)
34  ares_free(options->domains);
35  if(options->sortlist)
36  ares_free(options->sortlist);
37  if(options->lookups)
38  ares_free(options->lookups);
39  if(options->resolvconf_path)
40  ares_free(options->resolvconf_path);
41 }
42 
44 {
45  int i;
46  struct query *query;
47  struct list_node* list_head;
48  struct list_node* list_node;
49 
50  if (!channel)
51  return;
52 
53  list_head = &(channel->all_queries);
54  for (list_node = list_head->next; list_node != list_head; )
55  {
56  query = list_node->data;
57  list_node = list_node->next; /* since we're deleting the query */
58  query->callback(query->arg, ARES_EDESTRUCTION, 0, NULL, 0);
60  }
61 #ifndef NDEBUG
62  /* Freeing the query should remove it from all the lists in which it sits,
63  * so all query lists should be empty now.
64  */
65  assert(ares__is_list_empty(&(channel->all_queries)));
66  for (i = 0; i < ARES_QID_TABLE_SIZE; i++)
67  {
68  assert(ares__is_list_empty(&(channel->queries_by_qid[i])));
69  }
70  for (i = 0; i < ARES_TIMEOUT_TABLE_SIZE; i++)
71  {
72  assert(ares__is_list_empty(&(channel->queries_by_timeout[i])));
73  }
74 #endif
75 
77 
78  if (channel->domains) {
79  for (i = 0; i < channel->ndomains; i++)
80  ares_free(channel->domains[i]);
81  ares_free(channel->domains);
82  }
83 
84  if(channel->sortlist)
85  ares_free(channel->sortlist);
86 
87  if (channel->lookups)
88  ares_free(channel->lookups);
89 
90  if (channel->resolvconf_path)
91  ares_free(channel->resolvconf_path);
92 
94 }
95 
97 {
98  struct server_state *server;
99  int i;
100 
101  if (channel->servers)
102  {
103  for (i = 0; i < channel->nservers; i++)
104  {
105  server = &channel->servers[i];
107  assert(ares__is_list_empty(&server->queries_to_server));
108  }
109  ares_free(channel->servers);
110  channel->servers = NULL;
111  }
112  channel->nservers = -1;
113 }
ares__close_sockets
void ares__close_sockets(ares_channel channel, struct server_state *server)
Definition: ares__close_sockets.c:22
server_state
Definition: ares_private.h:161
ares_options
Definition: ares.h:259
ares.h
options
double_dict options[]
Definition: capstone_test.c:55
list_node::data
void * data
Definition: ares_llist.h:25
ARES_TIMEOUT_TABLE_SIZE
#define ARES_TIMEOUT_TABLE_SIZE
Definition: ares_private.h:319
ares__is_list_empty
int ares__is_list_empty(struct list_node *head)
Definition: ares_llist.c:41
server
std::unique_ptr< Server > server
Definition: channelz_service_test.cc:330
query
Definition: ares_private.h:198
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
ares_destroy_options
void ares_destroy_options(struct ares_options *options)
Definition: ares_destroy.c:25
query::arg
void * arg
Definition: ares_private.h:222
ARES_QID_TABLE_SIZE
#define ARES_QID_TABLE_SIZE
Definition: ares_private.h:316
ares_setup.h
ares_channeldata
Definition: ares_private.h:266
server
Definition: examples/python/async_streaming/server.py:1
ares__free_query
void ares__free_query(struct query *query)
Definition: ares_process.c:1500
ares_free
void(* ares_free)(void *ptr)=default_free
Definition: ares_library_init.c:60
list_node
Definition: ares_llist.h:22
ares_private.h
list_node::next
struct list_node * next
Definition: ares_llist.h:24
ares_destroy
void ares_destroy(ares_channel channel)
Definition: ares_destroy.c:43
query::callback
ares_callback callback
Definition: ares_private.h:221
ARES_EDESTRUCTION
#define ARES_EDESTRUCTION
Definition: ares.h:118
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
ares__destroy_servers_state
void ares__destroy_servers_state(ares_channel channel)
Definition: ares_destroy.c:96


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:43