 -
 -    pool->current = current ? current : new;
 -
-+    new->alloc = m;
-+    new->next = pool->d;
-+    pool->d = new;
-     return m;
+-    return m;
++    d->alloc = p;
++    d->next = pool->d;
++    pool->d = d;
++    return p;
  }
  
  

 
-    if ((u_char *) a + sizeof(ngx_array_t) == p->d.last) {
-        p->d.last = (u_char *) a;
-    }
+    ngx_pfree(p, a);
 }
 
 
@@ -65,29 +63,19 @@
 
         p = a->pool;
 

+        new = ngx_palloc(p, nalloc * a->size);
+        if (new == NULL) {
+            return NULL;
+        }
+
+        ngx_memcpy(new, a->elts, a->nelts * a->size);
+
+        link = ngx_palloc(p, sizeof(ngx_array_link_t));
+        if (link == NULL) {
+            ngx_pfree(p, new);
+            return NULL;
         }
+
+        link->next = a->old_elts;
+        link->elts = a->elts;
+        a->old_elts = link;
+
+        a->elts = new;
+        a->nalloc = nalloc;
     }
 
     elt = (u_char *) a->elts + a->size * a->nelts;
diff -urx '*~' -x '*.swp' nginx-1.2.1/src/core/ngx_array.h nginx-1.2.1-patched/src/core/ngx_array.h
--- nginx-1.2.1/src/core/ngx_array.h	2012-02-06 04:02:59.000000000 +0800
+++ nginx-1.2.1-patched/src/core/ngx_array.h	2012-06-20 23:25:38.800624960 +0800
@@ -13,12 +13,23 @@
 #include <ngx_core.h>
 
 
+typedef struct ngx_array_link_s ngx_array_link_t;
+
+
+struct ngx_array_link_s {
+    void                    *elts;
+    ngx_array_link_t        *next;
+};
+
+
 struct ngx_array_s {
     void        *elts;
     ngx_uint_t   nelts;
     size_t       size;
     ngx_uint_t   nalloc;
     ngx_pool_t  *pool;
+
+    ngx_array_link_t *old_elts;
 };
 
 
@@ -40,6 +51,7 @@
     array->size = size;
     array->nalloc = n;
     array->pool = pool;
+    array->old_elts = NULL;
 
     array->elts = ngx_palloc(pool, n * size);
     if (array->elts == NULL) {
diff -urx '*~' -x '*.swp' nginx-1.2.1/src/core/ngx_palloc.c nginx-1.2.1-patched/src/core/ngx_palloc.c
--- nginx-1.2.1/src/core/ngx_palloc.c	2012-02-06 04:02:59.000000000 +0800
+++ nginx-1.2.1-patched/src/core/ngx_palloc.c	2012-06-20 22:56:30.148073066 +0800
@@ -9,32 +9,23 @@
 #include <ngx_core.h>
 
