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

[or-cvs] Add more functions to free things to help dmalloc allong.



Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv19903/src/or

Modified Files:
	connection_edge.c directory.c dirserv.c main.c or.h 
	rendservice.c rephist.c routerlist.c 
Log Message:
Add more functions to free things to help dmalloc allong.

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_edge.c,v
retrieving revision 1.275
retrieving revision 1.276
diff -u -d -r1.275 -r1.276
--- connection_edge.c	5 Feb 2005 23:55:21 -0000	1.275
+++ connection_edge.c	10 Feb 2005 23:18:39 -0000	1.276
@@ -1071,6 +1071,13 @@
   }
 }
 
+void
+free_socks_policy(void)
+{
+  addr_policy_free(socks_policy);
+  socks_policy = NULL;
+}
+
 /** Return 1 if <b>addr</b> is permitted to connect to our socks port,
  * based on <b>socks_policy</b>. Else return 0.
  */
@@ -1242,6 +1249,12 @@
   strmap_foreach(client_dns_map, (strmap_foreach_fn)_remove_if_expired, &now);
 }
 
+void client_dns_free_all(void)
+{
+  strmap_free(client_dns_map, free);
+  client_dns_map = NULL;
+}
+
 /** Make connection redirection follow the provided list of
  * exit_redirect_t */
 void

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/directory.c,v
retrieving revision 1.211
retrieving revision 1.212
diff -u -d -r1.211 -r1.212
--- directory.c	10 Feb 2005 06:31:34 -0000	1.211
+++ directory.c	10 Feb 2005 23:18:39 -0000	1.212
@@ -88,6 +88,13 @@
   }
 }
 
+void
+free_dir_policy(void)
+{
+  addr_policy_free(dir_policy);
+  dir_policy = NULL;
+}
+
 /** Return 1 if <b>addr</b> is permitted to connect to our dir port,
  * based on <b>dir_policy</b>. Else return 0.
  */

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.141
retrieving revision 1.142
diff -u -d -r1.141 -r1.142
--- dirserv.c	31 Jan 2005 23:47:25 -0000	1.141
+++ dirserv.c	10 Feb 2005 23:18:39 -0000	1.142
@@ -998,3 +998,31 @@
   return compress ? the_runningrouters_z_len : the_runningrouters_len;
 }
 
+void
+dirserv_free_all(void)
+{
+  if (fingerprint_list) {
+    SMARTLIST_FOREACH(fingerprint_list, fingerprint_entry_t*, fp,
+                      { tor_free(fp->nickname);
+                        tor_free(fp->fingerprint);
+                        tor_free(fp); });
+    smartlist_free(fingerprint_list);
+    fingerprint_list = NULL;
+  }
+  if (descriptor_list) {
+    SMARTLIST_FOREACH(descriptor_list, descriptor_entry_t*, d,
+                      free_descriptor_entry(d));
+    smartlist_free(descriptor_list);
+    descriptor_list = NULL;
+  }
+  tor_free(the_directory);
+  tor_free(the_directory_z);
+  the_directory_len = 0;
+  the_directory_z_len = 0;
+  tor_free(cached_directory.dir);
+  tor_free(cached_directory.dir_z);
+  tor_free(cached_runningrouters.dir);
+  tor_free(cached_runningrouters.dir_z);
+  memset(&cached_directory, 0, sizeof(cached_directory));
+  memset(&cached_runningrouters, 0, sizeof(cached_runningrouters));
+}

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/main.c,v
retrieving revision 1.443
retrieving revision 1.444
diff -u -d -r1.443 -r1.444
--- main.c	9 Feb 2005 02:26:24 -0000	1.443
+++ main.c	10 Feb 2005 23:18:39 -0000	1.444
@@ -1304,8 +1304,23 @@
  *
  * Also valgrind should then report 0 reachable in its
  * leak report */
-void tor_free_all(void) {
-
+void tor_free_all(void)
+{
+  routerlist_free_current();
+  free_trusted_dir_servers();
+  client_dns_free_all();
+  free_socks_policy();
+  free_dir_policy();
+  dirserv_free_all();
+  rend_service_free_all();
+  rep_hist_free_all();
+  /* cache in dns.c */
+  /* onion queue in onion.c */
+  /* the circuits. */
+  /* the connections. */
+  /* the config */
+  /* My routerinfo_t */
+  /* all keys. */
 }
 
 /** Do whatever cleanup is necessary before shutting Tor down. */

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.532
retrieving revision 1.533
diff -u -d -r1.532 -r1.533
--- or.h	1 Feb 2005 00:37:16 -0000	1.532
+++ or.h	10 Feb 2005 23:18:39 -0000	1.533
@@ -1256,6 +1256,7 @@
 void connection_ap_attach_pending(void);
 
 void parse_socks_policy(void);
+void free_socks_policy(void);
 int socks_policy_permits_address(uint32_t addr);
 
 void client_dns_init(void);
@@ -1263,6 +1264,7 @@
 int client_dns_incr_failures(const char *address);
 void client_dns_set_entry(const char *address, uint32_t val);
 void client_dns_clean(void);
+void client_dns_free_all(void);
 void set_exit_redirects(smartlist_t *lst);
 typedef enum hostname_type_t {
   NORMAL_HOSTNAME, ONION_HOSTNAME, EXIT_HOSTNAME
@@ -1346,6 +1348,7 @@
 int connection_dir_finished_connecting(connection_t *conn);
 void connection_dir_connect_failed(connection_t *conn);
 void parse_dir_policy(void);
+void free_dir_policy(void);
 
 /********************************* dirserv.c ***************************/
 
@@ -1365,6 +1368,7 @@
 size_t dirserv_get_runningrouters(const char **rr, int compress);
 void dirserv_set_cached_directory(const char *directory, time_t when,
                                   int is_running_routers);
+void dirserv_free_all(void);
 
 /********************************* dns.c ***************************/
 
@@ -1492,6 +1496,8 @@
 void rep_hist_note_used_resolve(time_t now);
 int rep_hist_get_predicted_resolve(time_t now);
 
+void rep_hist_free_all(void);
+
 /********************************* rendclient.c ***************************/
 
 void rend_client_introcirc_has_opened(circuit_t *circ);
@@ -1558,6 +1564,7 @@
 void rend_service_relaunch_rendezvous(circuit_t *oldcirc);
 int rend_service_set_connection_addr_port(connection_t *conn, circuit_t *circ);
 void rend_service_dump_stats(int severity);
+void rend_service_free_all(void);
 
 /********************************* rendmid.c *******************************/
 int rend_mid_establish_intro(circuit_t *circ, const char *request, size_t request_len);
@@ -1646,6 +1653,8 @@
 time_t routerlist_get_published_time(void);
 void routerlist_free(routerlist_t *routerlist);
 void routerinfo_free(routerinfo_t *router);
+void routerlist_free_current(void);
+void free_trusted_dir_servers(void);
 routerinfo_t *routerinfo_copy(const routerinfo_t *router);
 void router_mark_as_down(const char *digest);
 void routerlist_remove_old_routers(int age);

Index: rendservice.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/rendservice.c,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -d -r1.115 -r1.116
--- rendservice.c	17 Jan 2005 18:13:09 -0000	1.115
+++ rendservice.c	10 Feb 2005 23:18:39 -0000	1.116
@@ -80,7 +80,7 @@
 /** Release all the storage held in rend_service_list, and allocate a new,
  * empty rend_service_list.
  */
-static void rend_service_free_all(void)
+void rend_service_free_all(void)
 {
   if (!rend_service_list) {
     rend_service_list = smartlist_create();
@@ -89,7 +89,7 @@
   SMARTLIST_FOREACH(rend_service_list, rend_service_t*, ptr,
                     rend_service_free(ptr));
   smartlist_free(rend_service_list);
-  rend_service_list = smartlist_create();
+  rend_service_list = NULL;
 }
 
 /** Validate <b>service</b> and add it to rend_service_list if possible.
@@ -190,8 +190,10 @@
   rend_service_t *service = NULL;
   rend_service_port_config_t *portcfg;
 
-  if (!validate_only)
+  if (!validate_only) {
     rend_service_free_all();
+    rend_service_list = smartlist_create();
+  }
 
   for (line = options->RendConfigLines; line; line = line->next) {
     if (!strcasecmp(line->key, "HiddenServiceDir")) {

Index: rephist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/rephist.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- rephist.c	17 Jan 2005 18:13:09 -0000	1.52
+++ rephist.c	10 Feb 2005 23:18:39 -0000	1.53
@@ -730,3 +730,9 @@
 void rep_hist_note_used_resolve(time_t now) { }
 int rep_hist_get_predicted_resolve(time_t now) { return 0; }
 
+void rep_hist_free_all(void)
+{
+  strmap_free(history_map, free_or_history);
+  tor_free(read_array);
+  tor_free(write_array);
+}

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.211
retrieving revision 1.212
diff -u -d -r1.211 -r1.212
--- routerlist.c	10 Feb 2005 07:00:23 -0000	1.211
+++ routerlist.c	10 Feb 2005 23:18:39 -0000	1.212
@@ -716,6 +716,22 @@
   tor_free(rl);
 }
 
+void routerlist_free_current(void)
+{
+  routerlist_free(routerlist);
+  routerlist = NULL;
+}
+
+void free_trusted_dir_servers(void)
+{
+  if (trusted_dir_servers) {
+    SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, ds,
+                      { tor_free(ds->address); tor_free(ds); });
+    smartlist_free(trusted_dir_servers);
+    trusted_dir_servers = NULL;
+  }
+}
+
 /** Mark the router with ID <b>digest</b> as non-running in our routerlist. */
 void router_mark_as_down(const char *digest) {
   routerinfo_t *router;