You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by sf...@apache.org on 2010/08/28 22:11:57 UTC

svn commit: r990435 - /apr/apr/trunk/memory/unix/apr_pools.c

Author: sf
Date: Sat Aug 28 20:11:57 2010
New Revision: 990435

URL: http://svn.apache.org/viewvc?rev=990435&view=rev
Log:
Fix various off-by-one errors related to current_free_index:
current_free_index counts pages of size BOUNDARY_SIZE, but every node contains
index + 1 of such pages

Modified:
    apr/apr/trunk/memory/unix/apr_pools.c

Modified: apr/apr/trunk/memory/unix/apr_pools.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/memory/unix/apr_pools.c?rev=990435&r1=990434&r2=990435&view=diff
==============================================================================
--- apr/apr/trunk/memory/unix/apr_pools.c (original)
+++ apr/apr/trunk/memory/unix/apr_pools.c Sat Aug 28 20:11:57 2010
@@ -259,7 +259,7 @@ apr_memnode_t *allocator_alloc(apr_alloc
                 allocator->max_index = max_index;
             }
 
-            allocator->current_free_index += node->index;
+            allocator->current_free_index += node->index + 1;
             if (allocator->current_free_index > allocator->max_free_index)
                 allocator->current_free_index = allocator->max_free_index;
 
@@ -299,7 +299,7 @@ apr_memnode_t *allocator_alloc(apr_alloc
         if (node) {
             *ref = node->next;
 
-            allocator->current_free_index += node->index;
+            allocator->current_free_index += node->index + 1;
             if (allocator->current_free_index > allocator->max_free_index)
                 allocator->current_free_index = allocator->max_free_index;
 
@@ -358,7 +358,7 @@ void allocator_free(apr_allocator_t *all
         index = node->index;
 
         if (max_free_index != APR_ALLOCATOR_MAX_FREE_UNLIMITED
-            && index > current_free_index) {
+            && index + 1 > current_free_index) {
             node->next = freelist;
             freelist = node;
         }
@@ -371,8 +371,8 @@ void allocator_free(apr_allocator_t *all
                 max_index = index;
             }
             allocator->free[index] = node;
-            if (current_free_index >= index)
-                current_free_index -= index;
+            if (current_free_index >= index + 1)
+                current_free_index -= index + 1;
             else
                 current_free_index = 0;
         }
@@ -382,8 +382,8 @@ void allocator_free(apr_allocator_t *all
              */
             node->next = allocator->free[0];
             allocator->free[0] = node;
-            if (current_free_index >= index)
-                current_free_index -= index;
+            if (current_free_index >= index + 1)
+                current_free_index -= index + 1;
             else
                 current_free_index = 0;
         }