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

[or-cvs] Free even more things on shutdown. Temporarily move tor_fr...



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

Modified Files:
	circuitlist.c config.c dns.c main.c onion.c or.h rephist.c 
	router.c 
Log Message:
Free even more things on shutdown.  Temporarily move tor_free_all out from #ifdef so it gets tested more.

Index: circuitlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/circuitlist.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- circuitlist.c	31 Jan 2005 03:47:38 -0000	1.25
+++ circuitlist.c	11 Feb 2005 01:26:46 -0000	1.26
@@ -149,6 +149,24 @@
   circuit_free_cpath_node(cpath);
 }
 
+/** Release all storage held by circuits. */
+void
+circuit_free_all(void)
+{
+  circuit_t *next;
+  while (global_circuitlist) {
+    next = global_circuitlist->next;
+    while (global_circuitlist->resolving_streams) {
+      connection_t *next;
+      next = global_circuitlist->resolving_streams->next_stream;
+      connection_free(global_circuitlist->resolving_streams);
+      global_circuitlist->resolving_streams = next;
+    }
+    circuit_free(global_circuitlist);
+    global_circuitlist = next;
+  }
+}
+
 /** Deallocate space associated with the cpath node <b>victim</b>. */
 static void
 circuit_free_cpath_node(crypt_path_t *victim) {

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.311
retrieving revision 1.312
diff -u -d -r1.311 -r1.312
--- config.c	5 Feb 2005 21:42:45 -0000	1.311
+++ config.c	11 Feb 2005 01:26:46 -0000	1.312
@@ -232,6 +232,13 @@
   global_options = new_val;
 }
 
+void
+config_free_all(void)
+{
+  options_free(global_options);
+  tor_free(config_fname);
+}
+
 /** Fetch the active option list, and take actions based on it. All
  * of the things we do should survive being done repeatedly.
  * Return 0 if all goes well, return -1 if it's time to die.

Index: dns.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dns.c,v
retrieving revision 1.135
retrieving revision 1.136
diff -u -d -r1.135 -r1.136
--- dns.c	5 Feb 2005 21:03:24 -0000	1.135
+++ dns.c	11 Feb 2005 01:26:46 -0000	1.136
@@ -99,6 +99,27 @@
   spawn_enough_dnsworkers();
 }
 
+static void
+_free_cached_resolve(struct cached_resolve *r) {
+  while(r->pending_connections) {
+    struct pending_connection_t *victim = r->pending_connections;
+    r->pending_connections = victim->next;
+    tor_free(victim);
+  }
+  tor_free(r);
+}
+
+void
+dns_free_all(void)
+{
+  struct cached_resolve *ptr, *next;
+  for (ptr = SPLAY_MIN(cache_tree, &cache_root); ptr != NULL; ptr = next) {
+    next = SPLAY_NEXT(cache_tree, &cache_root, ptr);
+    SPLAY_REMOVE(cache_tree, &cache_root, ptr);
+    _free_cached_resolve(ptr);
+  }
+}
+
 /** Linked list of resolved addresses, oldest to newest. */
 static struct cached_resolve *oldest_cached_resolve = NULL;
 static struct cached_resolve *newest_cached_resolve = NULL;

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/main.c,v
retrieving revision 1.444
retrieving revision 1.445
diff -u -d -r1.444 -r1.445
--- main.c	10 Feb 2005 23:18:39 -0000	1.444
+++ main.c	11 Feb 2005 01:26:46 -0000	1.445
@@ -1314,13 +1314,14 @@
   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. */
+  dns_free_all();
+  clear_pending_onions();
+  circuit_free_all();
+  connection_free_all();
+  config_free_all();
+  router_free_all_keys();
+  /* stuff in main.c */
+  smartlist_free(closeable_connection_lst);
 }
 
 /** Do whatever cleanup is necessary before shutting Tor down. */
@@ -1333,8 +1334,8 @@
   crypto_global_cleanup();
   if (accounting_is_enabled(options))
     accounting_record_bandwidth_usage(time(NULL));
+  tor_free_all(); /* move tor_free_all back into the ifdef below later. XXX*/
 #ifdef USE_DMALLOC
-  tor_free_all();
   dmalloc_log_unfreed();
   dmalloc_shutdown();
 #endif

Index: onion.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/onion.c,v
retrieving revision 1.174
retrieving revision 1.175
diff -u -d -r1.174 -r1.175
--- onion.c	31 Jan 2005 04:03:57 -0000	1.174
+++ onion.c	11 Feb 2005 01:26:47 -0000	1.175
@@ -316,3 +316,15 @@
   return 0;
 }
 
+/** Remove all circuits from the pending list.  Called from tor_free_all. */
+void
+clear_pending_onions(void)
+{
+  while (ol_list) {
+    struct onion_queue_t *victim = ol_list;
+    ol_list = victim->next;
+    tor_free(victim);
+  }
+  ol_list = ol_tail = NULL;
+  ol_length = 0;
+}

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.533
retrieving revision 1.534
diff -u -d -r1.533 -r1.534
--- or.h	10 Feb 2005 23:18:39 -0000	1.533
+++ or.h	11 Feb 2005 01:26:47 -0000	1.534
@@ -1105,6 +1105,7 @@
 
 void assert_cpath_layer_ok(const crypt_path_t *cp);
 void assert_circuit_ok(const circuit_t *c);
+void circuit_free_all(void);
 
 /********************************* circuituse.c ************************/
 
@@ -1144,6 +1145,7 @@
 or_options_t *get_options(void);
 void set_options(or_options_t *new_val);
 int options_act(void);
+void config_free_all(void);
 
 int config_get_lines(char *string, struct config_line_t **result);
 void config_free_lines(struct config_line_t *front);
@@ -1373,6 +1375,7 @@
 /********************************* dns.c ***************************/
 
 void dns_init(void);
+void dns_free_all(void);
 int connection_dns_finished_flushing(connection_t *conn);
 int connection_dns_reached_eof(connection_t *conn);
 int connection_dns_process_inbuf(connection_t *conn);
@@ -1451,6 +1454,8 @@
                              char *key_out,
                              size_t key_out_len);
 
+void clear_pending_onions(void);
+
 /********************************* relay.c ***************************/
 
 extern unsigned long stats_n_relay_cells_relayed;
@@ -1601,6 +1606,7 @@
                                  crypto_pk_env_t *ident_key);
 int is_legal_nickname(const char *s);
 int is_legal_nickname_or_hexdigest(const char *s);
+void router_free_all_keys(void);
 
 /********************************* routerlist.c ***************************/
 

Index: rephist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/rephist.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- rephist.c	10 Feb 2005 23:18:39 -0000	1.53
+++ rephist.c	11 Feb 2005 01:26:47 -0000	1.54
@@ -106,8 +106,9 @@
 }
 
 static void
-free_or_history(or_history_t *hist)
+free_or_history(void *_hist)
 {
+  or_history_t *hist = _hist;
   strmap_free(hist->link_history_map, _free_link_history);
   tor_free(hist);
 }

Index: router.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/router.c,v
retrieving revision 1.144
retrieving revision 1.145
diff -u -d -r1.144 -r1.145
--- router.c	2 Feb 2005 04:15:40 -0000	1.144
+++ router.c	11 Feb 2005 01:26:47 -0000	1.145
@@ -829,3 +829,16 @@
   return len == HEX_DIGEST_LEN+1 && strspn(s+1,HEX_CHARACTERS)==len-1;
 }
 
+void router_free_all_keys(void)
+{
+  if (onionkey)
+    crypto_free_pk_env(onionkey);
+  if (lastonionkey)
+    crypto_free_pk_env(lastonionkey);
+  if (identitykey)
+    crypto_free_pk_env(identitykey);
+  if (key_lock)
+    tor_mutex_free(key_lock);
+  if (desc_routerinfo)
+    routerinfo_free(desc_routerinfo);
+}