]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix memory leak in TestingEnableCellStatsEvent
authorNick Mathewson <nickm@torproject.org>
Mon, 28 Mar 2016 14:37:22 +0000 (10:37 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 28 Mar 2016 15:12:15 +0000 (11:12 -0400)
Only when we were actually flushing the cell stats to a controller
would we free them.  Thus, they could stay in RAM even after the
circuit was freed (eg if we didn't have any controllers).

Fixes bug 18673; bugfix on 0.2.5.1-alpha.

changes/bug18673 [new file with mode: 0644]
src/or/circuitlist.c
src/or/circuitlist.h
src/or/control.c

diff --git a/changes/bug18673 b/changes/bug18673
new file mode 100644 (file)
index 0000000..5d61617
--- /dev/null
@@ -0,0 +1,4 @@
+  o Minor bugfixes (memory leak):
+    - Fix a small memory leak that would occur when the
+      TestingEnableCellStatsEvent option was turned on.  Fixes bug 18673;
+      bugfix on 0.2.5.2-alpha.
index d6532ddc5f2e76a8715ef847b0cd8d2f019ff30e..670c5b3c192ad542499f24f5308ae912449d6247 100644 (file)
@@ -756,6 +756,18 @@ or_circuit_new(circid_t p_circ_id, channel_t *p_chan)
   return circ;
 }
 
+/** Free all storage held in circ->testing_cell_stats */
+void
+circuit_clear_testing_cell_stats(circuit_t *circ)
+{
+  if (!circ)
+    return;
+  SMARTLIST_FOREACH(circ->testing_cell_stats, testing_cell_stats_entry_t *,
+                    ent, tor_free(ent));
+  smartlist_free(circ->testing_cell_stats);
+  circ->testing_cell_stats = NULL;
+}
+
 /** Deallocate space associated with circ.
  */
 STATIC void
@@ -767,6 +779,8 @@ circuit_free(circuit_t *circ)
   if (!circ)
     return;
 
+  circuit_clear_testing_cell_stats(circ);
+
   if (CIRCUIT_IS_ORIGIN(circ)) {
     origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ);
     mem = ocirc;
index e4f1f47ce60a85027129019f91fc0c42b02fc32f..2707b426ab4a686463998f729d5eacb308da9870 100644 (file)
@@ -71,6 +71,8 @@ void assert_circuit_ok(const circuit_t *c);
 void circuit_free_all(void);
 void circuits_handle_oom(size_t current_allocation);
 
+void circuit_clear_testing_cell_stats(circuit_t *circ);
+
 void channel_note_destroy_pending(channel_t *chan, circid_t id);
 MOCK_DECL(void, channel_note_destroy_not_pending,
           (channel_t *chan, circid_t id));
index 2bec8f9317d4d1566add70651172ed0cf468dd26..655b4dd335d48d43b318ddf883931dd40247977e 100644 (file)
@@ -4971,7 +4971,7 @@ sum_up_cell_stats_by_command(circuit_t *circ, cell_stats_t *cell_stats)
 {
   memset(cell_stats, 0, sizeof(cell_stats_t));
   SMARTLIST_FOREACH_BEGIN(circ->testing_cell_stats,
-                          testing_cell_stats_entry_t *, ent) {
+                          const testing_cell_stats_entry_t *, ent) {
     tor_assert(ent->command <= CELL_COMMAND_MAX_);
     if (!ent->removed && !ent->exitward) {
       cell_stats->added_cells_appward[ent->command] += 1;
@@ -4984,10 +4984,8 @@ sum_up_cell_stats_by_command(circuit_t *circ, cell_stats_t *cell_stats)
       cell_stats->removed_cells_exitward[ent->command] += 1;
       cell_stats->total_time_exitward[ent->command] += ent->waiting_time * 10;
     }
-    tor_free(ent);
   } SMARTLIST_FOREACH_END(ent);
-  smartlist_free(circ->testing_cell_stats);
-  circ->testing_cell_stats = NULL;
+  circuit_clear_testing_cell_stats(circ);
 }
 
 /** Helper: append a cell statistics string to <code>event_parts</code>,