]> granicus.if.org Git - apache/commitdiff
This fixes a problem where the underlying cache code
authorPaul J. Reder <rederpj@apache.org>
Thu, 14 Nov 2002 02:04:01 +0000 (02:04 +0000)
committerPaul J. Reder <rederpj@apache.org>
Thu, 14 Nov 2002 02:04:01 +0000 (02:04 +0000)
indicated that there was one more element on the cache
than there actually was. This happened since element 0
exists but is not used. This code allocates the correct
number of useable elements and reports the number of
actually used elements. The previous code only allowed
MCacheMaxObjectCount-1 objects to be stored in the
cache. [Paul J. Reder]

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@97510 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
modules/experimental/cache_pqueue.c

diff --git a/CHANGES b/CHANGES
index eadedeba833c938806fea99b49470cc0bbcfc16e..6e0f726ada860026ea93c69084f18aceaecb5159 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,14 @@
 Changes with Apache 2.0.44
 
+  *) This fixes a problem where the underlying cache code
+     indicated that there was one more element on the cache
+     than there actually was. This happened since element 0
+     exists but is not used. This code allocates the correct
+     number of useable elements and reports the number of
+     actually used elements. The previous code only allowed
+     MCacheMaxObjectCount-1 objects to be stored in the
+     cache. [Paul J. Reder]
+
   *) mod_setenvif: Add SERVER_ADDR special keyword to allow
      envariable setting according to the server IP address
      which received the request.  [Ken Coar]
index 5ded1907979eef2651cadb52d1506f9f27100576..18edb804d6c38a1fb61fe6e1cc55ff9c683ec7a0 100644 (file)
@@ -98,11 +98,12 @@ cache_pqueue_t *cache_pq_init(apr_ssize_t n,
         return NULL;
     }
 
-    if (!(q->d = malloc(sizeof(void*) * n))) {
+    /* Need to allocate n+1 elements since element 0 isn't used. */
+    if (!(q->d = malloc(sizeof(void*) * (n+1)))) {
         free(q);
         return NULL;
     }
-    q->avail = q->step = n;
+    q->avail = q->step = (n+1);  /* see comment above about n+1 */
     q->pri = pri;
     q->size = 1;
     q->get = get;
@@ -122,7 +123,8 @@ void cache_pq_free(cache_pqueue_t *q)
  */
 apr_ssize_t cache_pq_size(cache_pqueue_t *q)
 {
-    return q->size;
+    /* queue element 0 exists but doesn't count since it isn't used. */
+    return (q->size - 1);
 }
 
 static void cache_pq_bubble_up(cache_pqueue_t *q, apr_ssize_t i)