[or-cvs] r10313: When freeing slack buffers, free the buffers at the end of t (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Thu May 24 18:12:41 UTC 2007


Author: nickm
Date: 2007-05-24 14:12:41 -0400 (Thu, 24 May 2007)
New Revision: 10313

Modified:
   tor/trunk/
   tor/trunk/src/or/buffers.c
Log:
 r12934 at catbus:  nickm | 2007-05-24 14:11:18 -0400
 When freeing slack buffers, free the buffers at the end of the freelist first.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r12934] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/src/or/buffers.c
===================================================================
--- tor/trunk/src/or/buffers.c	2007-05-24 18:12:38 UTC (rev 10312)
+++ tor/trunk/src/or/buffers.c	2007-05-24 18:12:41 UTC (rev 10313)
@@ -259,18 +259,37 @@
   for (j = 0; j < 2; ++j) {
     free_mem_list_t *list = j ? &free_mem_list_16k : &free_mem_list_4k;
     if (list->lowwater > list->slack) {
-      int i;
+      int i, n_to_skip, n_to_free;
+      char **ptr;
       log_info(LD_GENERAL, "We haven't used %d/%d allocated %d-byte buffer "
                "memory chunks since the last call; freeing all but %d of them",
                list->lowwater, list->len, (int)list->chunksize, list->slack);
+      /* Skip over the slack and non-lowwater entries */
+      n_to_free = list->lowwater - list->slack;
+      n_to_skip = list->len - n_to_free;
+      for (ptr = &list->list, i = 0; i < n_to_skip; ++i) {
+        char *mem = *ptr;
+        tor_assert(mem);
+        ptr = (char**)mem;
+      }
+      /* And free the remaining entries. */
+      for (i = 0; i < n_to_free; ++i) {
+        char *mem = *ptr;
+        tor_assert(mem);
+        *ptr = *(char**)mem;
+        tor_free(mem);
+        --list->len;
+      }
+#if 0
+      /* XXXX020 Put this code back if the above gives us nasty segfaults. */
       for (i = list->slack; i < list->lowwater; ++i) {
-        /* XXXX we should really free the last few entries, not the first. */
         char *mem = list->list;
         tor_assert(mem);
         list->list = *(char**)mem;
         tor_free(mem);
         --list->len;
       }
+#endif
     }
     list->lowwater = list->len;
   }



More information about the tor-commits mailing list