From: Paul J. Reder Date: Thu, 14 Nov 2002 02:04:01 +0000 (+0000) Subject: This fixes a problem where the underlying cache code X-Git-Tag: 2.0.44~63 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3a60663585dbaa46714271892b4e5668089265b3;p=apache 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] git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@97510 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index eadedeba83..6e0f726ada 100644 --- 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] diff --git a/modules/experimental/cache_pqueue.c b/modules/experimental/cache_pqueue.c index 5ded190797..18edb804d6 100644 --- a/modules/experimental/cache_pqueue.c +++ b/modules/experimental/cache_pqueue.c @@ -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)