apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: rev 65594 - in apr/apr/branches/APR_0_9_BRANCH: . tables
Date Sun, 14 Nov 2004 12:00:25 GMT
Author: brane
Date: Sun Nov 14 04:00:24 2004
New Revision: 65594

Modified:
   apr/apr/branches/APR_0_9_BRANCH/CHANGES
   apr/apr/branches/APR_0_9_BRANCH/tables/apr_hash.c
Log:
Merged trunk r65572 to APU_0_9_BRANCH.


Modified: apr/apr/branches/APR_0_9_BRANCH/CHANGES
==============================================================================
--- apr/apr/branches/APR_0_9_BRANCH/CHANGES	(original)
+++ apr/apr/branches/APR_0_9_BRANCH/CHANGES	Sun Nov 14 04:00:24 2004
@@ -1,5 +1,8 @@
 Changes with APR 0.9.5
 
+  *) Prevent unbounded memory use during repeated operations on a hash table.
+     [Julian Foad <julianfoad btopenworld.com>
+
   *) fix apr_file_dup and apr_file_dup2 win32 implementations
      to create a mutex [Steve Hay <steve.hay uk.radan.com>]
 

Modified: apr/apr/branches/APR_0_9_BRANCH/tables/apr_hash.c
==============================================================================
--- apr/apr/branches/APR_0_9_BRANCH/tables/apr_hash.c	(original)
+++ apr/apr/branches/APR_0_9_BRANCH/tables/apr_hash.c	Sun Nov 14 04:00:24 2004
@@ -72,6 +72,7 @@
     apr_hash_entry_t   **array;
     apr_hash_index_t     iterator;  /* For apr_hash_first(NULL, ...) */
     unsigned int         count, max;
+    apr_hash_entry_t    *free;  /* List of recycled entries */
 };
 
 #define INITIAL_MAX 15 /* tunable == 2^n - 1 */
@@ -91,6 +92,7 @@
     apr_hash_t *ht;
     ht = apr_palloc(pool, sizeof(apr_hash_t));
     ht->pool = pool;
+    ht->free = NULL;
     ht->count = 0;
     ht->max = INITIAL_MAX;
     ht->array = alloc_array(ht, ht->max);
@@ -243,7 +245,10 @@
         return hep;
 
     /* add a new entry for non-NULL values */
-    he = apr_palloc(ht->pool, sizeof(*he));
+    if (he = ht->free)
+        ht->free = he->next;
+    else
+        he = apr_palloc(ht->pool, sizeof(*he));
     he->next = NULL;
     he->hash = hash;
     he->key  = key;
@@ -265,6 +270,7 @@
                     sizeof(*ht->array) * (orig->max + 1) +
                     sizeof(apr_hash_entry_t) * orig->count);
     ht->pool = pool;
+    ht->free = NULL;
     ht->count = orig->count;
     ht->max = orig->max;
     ht->array = (apr_hash_entry_t **)((char *)ht + sizeof(apr_hash_t));
@@ -311,7 +317,10 @@
     if (*hep) {
         if (!val) {
             /* delete entry */
+            apr_hash_entry_t *old = *hep;
             *hep = (*hep)->next;
+            old->next = ht->free;
+            ht->free = old;
             --ht->count;
         }
         else {
@@ -374,6 +383,7 @@
 
     res = apr_palloc(p, sizeof(apr_hash_t));
     res->pool = p;
+    res->free = NULL;
     res->count = base->count;
     res->max = (overlay->max > base->max) ? overlay->max : base->max;
     if (base->count + overlay->count > res->max) {

Mime
View raw message