]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
r12458@catbus: nickm | 2007-04-19 15:52:23 -0400
authorNick Mathewson <nickm@torproject.org>
Thu, 19 Apr 2007 19:52:30 +0000 (19:52 +0000)
committerNick Mathewson <nickm@torproject.org>
Thu, 19 Apr 2007 19:52:30 +0000 (19:52 +0000)
 Fix a bug in displaying memory pool usage.  Also dump cell allocation, and track padded_cell_ts as they are allocated and freed, to make sure we are not leaking cells.

svn:r9992

src/common/mempool.c
src/or/relay.c

index 9f1fd394bd77f16b11786e6ad59d1f884c81b557..dcdb27c3c78f87fa564b1a3499d3f3a5ab01d054 100644 (file)
@@ -517,7 +517,7 @@ mp_pool_log_status(mp_pool_t *pool, int severity)
          " bytes in %d partially full chunks",
          U64_PRINTF_ARG(bu), U64_PRINTF_ARG(ba), n_used);
   bytes_used += bu;
-  bytes_allocated += bu;
+  bytes_allocated += ba;
   bu = ba = 0;
   for (chunk = pool->full_chunks; chunk; chunk = chunk->next) {
     ++n_full;
@@ -528,7 +528,7 @@ mp_pool_log_status(mp_pool_t *pool, int severity)
          " bytes in %d full chunks",
          U64_PRINTF_ARG(bu), U64_PRINTF_ARG(ba), n_full);
   bytes_used += bu;
-  bytes_allocated += bu;
+  bytes_allocated += ba;
 
   log_fn(severity, LD_MM, "Total: "U64_FORMAT"/"U64_FORMAT" bytes allocated "
          "for cell pools are full.",
index a5bea0a71753f29f72a349cae992c174d1abbf1b..933d07928510683e3a320335f1b170e197732505 100644 (file)
@@ -1478,6 +1478,9 @@ circuit_consider_sending_sendme(circuit_t *circ, crypt_path_t *layer_hint)
 #define assert_active_circuits_ok_paranoid(conn)
 #endif
 
+/** DOCDOC */
+static int total_cells_allocated = 0;
+
 #ifdef ENABLE_CELL_POOL
 static mp_pool_t *cell_pool = NULL;
 /** Allocate structures to hold cells. */
@@ -1509,6 +1512,7 @@ clean_cell_pool(void)
 static INLINE void
 packed_cell_free(packed_cell_t *cell)
 {
+  --total_cells_allocated;
   mp_pool_release(cell);
 }
 
@@ -1516,11 +1520,23 @@ packed_cell_free(packed_cell_t *cell)
 static INLINE packed_cell_t *
 packed_cell_alloc(void)
 {
+  ++total_cells_allocated;
   return mp_pool_get(cell_pool);
 }
 void
 dump_cell_pool_usage(int severity)
 {
+  circuit_t *c;
+  int n_circs = 0;
+  int n_cells = 0;
+  for (c = _circuit_get_global_list(); c; c = c->next) {
+    n_cells += c->n_conn_cells.n;
+    if (!CIRCUIT_IS_ORIGIN(c))
+      n_cells += TO_OR_CIRCUIT(c)->p_conn_cells.n;
+    ++n_circs;
+  }
+  log(severity, LD_MM, "%d cells allocated on %d circuits. %d cells leaked.",
+      n_cells, n_circs, total_cells_allocated - n_cells);
   mp_pool_log_status(cell_pool, severity);
 }
 #else
@@ -1544,12 +1560,14 @@ clean_cell_pool(void)
 static INLINE void
 packed_cell_free(packed_cell_t *cell)
 {
+  --total_cells_allocated;
   tor_free(cell);
 }
 
 static INLINE packed_cell_t *
 packed_cell_alloc(void)
 {
+  ++total_cells_allocated;
   return tor_malloc(sizeof(packed_cell_t));
 }
 void