[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r8503: Minor fix: add code to eventdns so it can free memory on shu (tor/trunk/src/or)



Author: nickm
Date: 2006-09-25 16:38:58 -0400 (Mon, 25 Sep 2006)
New Revision: 8503

Modified:
   tor/trunk/src/or/dns.c
   tor/trunk/src/or/eventdns.c
   tor/trunk/src/or/eventdns.h
   tor/trunk/src/or/main.c
Log:
Minor fix: add code to eventdns so it can free memory on shutdown. This should help valgrind and dmalloc freak out less.

Modified: tor/trunk/src/or/dns.c
===================================================================
--- tor/trunk/src/or/dns.c	2006-09-25 18:46:29 UTC (rev 8502)
+++ tor/trunk/src/or/dns.c	2006-09-25 20:38:58 UTC (rev 8503)
@@ -1557,7 +1557,8 @@
     if (evdns_err_is_transient(result))
       status = DNS_RESOLVE_FAILED_TRANSIENT;
   }
-  dns_found_answer(string_address, is_reverse, addr, hostname, status, ttl);
+  if (result != DNS_ERR_SHUTDOWN)
+    dns_found_answer(string_address, is_reverse, addr, hostname, status, ttl);
   tor_free(string_address);
 }
 

Modified: tor/trunk/src/or/eventdns.c
===================================================================
--- tor/trunk/src/or/eventdns.c	2006-09-25 18:46:29 UTC (rev 8502)
+++ tor/trunk/src/or/eventdns.c	2006-09-25 20:38:58 UTC (rev 8503)
@@ -2294,7 +2294,7 @@
 }
 
 int
-evdns_init()
+evdns_init(void)
 {
         int res = 0;
 #ifdef MS_WINDOWS
@@ -2308,6 +2308,45 @@
 
 #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:
 // tab-width: 4
 // c-basic-offset: 4

Modified: tor/trunk/src/or/eventdns.h
===================================================================
--- tor/trunk/src/or/eventdns.h	2006-09-25 18:46:29 UTC (rev 8502)
+++ tor/trunk/src/or/eventdns.h	2006-09-25 20:38:58 UTC (rev 8503)
@@ -36,6 +36,8 @@
 #define DNS_ERR_UNKNOWN 66
 /* Communication with the server timed out */
 #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_PTR 2
@@ -50,6 +52,7 @@
 typedef void (*evdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg);
 
 int evdns_init(void);
+void evdns_shutdown(int fail_requests);
 int evdns_nameserver_add(unsigned long int address);
 int evdns_count_nameservers(void);
 int evdns_clear_nameservers_and_suspend(void);

Modified: tor/trunk/src/or/main.c
===================================================================
--- tor/trunk/src/or/main.c	2006-09-25 18:46:29 UTC (rev 8502)
+++ tor/trunk/src/or/main.c	2006-09-25 20:38:58 UTC (rev 8503)
@@ -16,6 +16,9 @@
 #ifdef USE_DMALLOC
 #include <dmalloc.h>
 #endif
+#ifdef USE_EVENTDNS
+void evdns_shutdown(int);
+#endif
 
 /********* PROTOTYPES **********/
 
@@ -1548,6 +1551,11 @@
 void
 tor_free_all(int postfork)
 {
+#ifdef USE_EVENTDNS
+  if (!postfork) {
+    evdns_shutdown(1);
+  }
+#endif
   routerlist_free_all();
   addressmap_free_all();
   set_exit_redirects(NULL); /* free the registered exit redirects */