[or-cvs] [tor/master] Make buf_shrink_freelists warn, not crash, when n_to_skip is too high

nickm at torproject.org nickm at torproject.org
Mon Aug 16 04:25:30 UTC 2010


Author: Nick Mathewson <nickm at torproject.org>
Date: Tue, 10 Aug 2010 15:58:41 -0400
Subject: Make buf_shrink_freelists warn, not crash, when n_to_skip is too high
Commit: 8150e2ad245e9d2dbfb35ae53384424efd749890

This mitigates bug 1125, but doesn't fix its root cause (whatever
that is).
---
 changes/warn1125 |    5 +++++
 src/or/buffers.c |   19 +++++++++++++++----
 2 files changed, 20 insertions(+), 4 deletions(-)
 create mode 100644 changes/warn1125

diff --git a/changes/warn1125 b/changes/warn1125
new file mode 100644
index 0000000..3b723e7
--- /dev/null
+++ b/changes/warn1125
@@ -0,0 +1,5 @@
+  o Minor bugfixes:
+    - Instead of giving an assertion failure on an internal mismatch
+      on estimated freelist size, just log a BUG warning and try later.
+      Mitigates but does not fix bug 1125.
+
diff --git a/src/or/buffers.c b/src/or/buffers.c
index 3ba2760..e842263 100644
--- a/src/or/buffers.c
+++ b/src/or/buffers.c
@@ -270,14 +270,25 @@ buf_shrink_freelists(int free_all)
         (freelists[i].lowest_length - slack);
       int n_to_skip = freelists[i].cur_length - n_to_free;
       int orig_n_to_free = n_to_free, n_freed=0;
+      int orig_n_to_skip = n_to_skip;
       int new_length = n_to_skip;
       chunk_t **chp = &freelists[i].head;
       chunk_t *chunk;
-      log_info(LD_MM, "Cleaning freelist for %d-byte chunks: keeping %d, "
-               "dropping %d.",
-               (int)freelists[i].alloc_size, n_to_skip, n_to_free);
+      log_info(LD_MM, "Cleaning freelist for %d-byte chunks: length %d, "
+               "keeping %d, dropping %d.",
+               (int)freelists[i].alloc_size, freelists[i].cur_length,
+               n_to_skip, n_to_free);
+      tor_assert(n_to_skip + n_to_free == freelists[i].cur_length);
       while (n_to_skip) {
-        tor_assert((*chp)->next);
+        if (! (*chp)->next) {
+          log_warn(LD_BUG, "I wanted to skip %d chunks in the freelist for "
+                   "%d-byte chunks, but only found %d. (Length %d)",
+                   orig_n_to_skip, (int)freelists[i].alloc_size,
+                   orig_n_to_skip-n_to_skip, freelists[i].cur_length);
+          assert_freelist_ok(&freelists[i]);
+          return;
+        }
+        // tor_assert((*chp)->next);
         chp = &(*chp)->next;
         --n_to_skip;
       }
-- 
1.7.1



More information about the tor-commits mailing list