Minor fix: add code to eventdns so it can free memory on shutdown. This should help valgrind and dmalloc freak out less.

svn:r8503
This commit is contained in:
Nick Mathewson 2006-09-25 20:38:58 +00:00
parent 52e179b942
commit 01f9e97d43
4 changed files with 53 additions and 2 deletions

View File

@ -1557,6 +1557,7 @@ evdns_callback(int result, char type, int count, int ttl, void *addresses,
if (evdns_err_is_transient(result)) if (evdns_err_is_transient(result))
status = DNS_RESOLVE_FAILED_TRANSIENT; status = DNS_RESOLVE_FAILED_TRANSIENT;
} }
if (result != DNS_ERR_SHUTDOWN)
dns_found_answer(string_address, is_reverse, addr, hostname, status, ttl); dns_found_answer(string_address, is_reverse, addr, hostname, status, ttl);
tor_free(string_address); tor_free(string_address);
} }

View File

@ -2294,7 +2294,7 @@ main(int c, char **v) {
} }
int int
evdns_init() evdns_init(void)
{ {
int res = 0; int res = 0;
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
@ -2308,6 +2308,45 @@ evdns_init()
#endif #endif
void
evdns_shutdown(int fail_requests)
{
struct nameserver *server, *server_next;
struct search_domain *dom, *dom_next;
while (req_head) {
if (fail_requests)
reply_callback(req_head, 0, DNS_ERR_SHUTDOWN, NULL);
request_finished(req_head, &req_head);
}
while (req_waiting_head) {
if (fail_requests)
reply_callback(req_waiting_head, 0, DNS_ERR_SHUTDOWN, NULL);
request_finished(req_waiting_head, &req_waiting_head);
}
global_requests_inflight = global_requests_waiting = 0;
for (server = server_head; server; server = server_next) {
server_next = server->next;
if (server->socket >= 0)
CLOSE_SOCKET(server->socket);
(void) event_del(&server->event);
free(server);
}
server_head = NULL;
global_good_nameservers = 0;
if (global_search_state) {
for (dom = global_search_state->head; dom; dom = dom_next) {
dom_next = dom->next;
free(dom);
}
free(global_search_state);
global_search_state = NULL;
}
evdns_log_fn = NULL;
}
// Local Variables: // Local Variables:
// tab-width: 4 // tab-width: 4
// c-basic-offset: 4 // c-basic-offset: 4

View File

@ -36,6 +36,8 @@
#define DNS_ERR_UNKNOWN 66 #define DNS_ERR_UNKNOWN 66
/* Communication with the server timed out */ /* Communication with the server timed out */
#define DNS_ERR_TIMEOUT 67 #define DNS_ERR_TIMEOUT 67
/* The request was canceled because the DNS subsystem was shut down. */
#define DNS_ERR_SHUTDOWN 68
#define DNS_IPv4_A 1 #define DNS_IPv4_A 1
#define DNS_PTR 2 #define DNS_PTR 2
@ -50,6 +52,7 @@
typedef void (*evdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg); typedef void (*evdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg);
int evdns_init(void); int evdns_init(void);
void evdns_shutdown(int fail_requests);
int evdns_nameserver_add(unsigned long int address); int evdns_nameserver_add(unsigned long int address);
int evdns_count_nameservers(void); int evdns_count_nameservers(void);
int evdns_clear_nameservers_and_suspend(void); int evdns_clear_nameservers_and_suspend(void);

View File

@ -16,6 +16,9 @@ const char main_c_id[] =
#ifdef USE_DMALLOC #ifdef USE_DMALLOC
#include <dmalloc.h> #include <dmalloc.h>
#endif #endif
#ifdef USE_EVENTDNS
void evdns_shutdown(int);
#endif
/********* PROTOTYPES **********/ /********* PROTOTYPES **********/
@ -1548,6 +1551,11 @@ tor_init(int argc, char *argv[])
void void
tor_free_all(int postfork) tor_free_all(int postfork)
{ {
#ifdef USE_EVENTDNS
if (!postfork) {
evdns_shutdown(1);
}
#endif
routerlist_free_all(); routerlist_free_all();
addressmap_free_all(); addressmap_free_all();
set_exit_redirects(NULL); /* free the registered exit redirects */ set_exit_redirects(NULL); /* free the registered exit redirects */