nginx-0.3.24-RELEASE import

    *) Workaround: for bug in FreeBSD kqueue.

    *) Bugfix: now a response generated by the "post_action" directive is
       not transferred to a client.

    *) Bugfix: the memory leaks were occurring if many log files were used.

    *) Bugfix: the first "proxy_redirect" directive was working inside one
       location.

    *) Bugfix: on 64-bit platforms segmentation fault may occurred on start
       if the many names were used in the "server_name" directives; the bug
       had appeared in 0.3.18.
diff --git a/src/core/nginx.h b/src/core/nginx.h
index 0912ac5..c2f9737 100644
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -8,7 +8,7 @@
 #define _NGINX_H_INCLUDED_
 
 
-#define NGINX_VER          "nginx/0.3.23"
+#define NGINX_VER          "nginx/0.3.24"
 
 #define NGINX_VAR          "NGINX"
 #define NGX_OLDPID_EXT     ".oldbin"
diff --git a/src/core/ngx_array.c b/src/core/ngx_array.c
index b6167af..1b9f7cb 100644
--- a/src/core/ngx_array.c
+++ b/src/core/ngx_array.c
@@ -8,7 +8,8 @@
 #include <ngx_core.h>
 
 
-ngx_array_t *ngx_array_create(ngx_pool_t *p, ngx_uint_t n, size_t size)
+ngx_array_t *
+ngx_array_create(ngx_pool_t *p, ngx_uint_t n, size_t size)
 {
     ngx_array_t *a;
 
@@ -31,7 +32,8 @@
 }
 
 
-void ngx_array_destroy(ngx_array_t *a)
+void
+ngx_array_destroy(ngx_array_t *a)
 {
     ngx_pool_t  *p;
 
@@ -47,7 +49,8 @@
 }
 
 
-void *ngx_array_push(ngx_array_t *a)
+void *
+ngx_array_push(ngx_array_t *a)
 {
     void        *elt, *new;
     size_t       size;
@@ -92,7 +95,8 @@
 }
 
 
-void *ngx_array_push_n(ngx_array_t *a, ngx_uint_t n)
+void *
+ngx_array_push_n(ngx_array_t *a, ngx_uint_t n)
 {
     void        *elt, *new;
     size_t       size;
diff --git a/src/core/ngx_conf_file.c b/src/core/ngx_conf_file.c
index 589eb0e..ab097c0 100644
--- a/src/core/ngx_conf_file.c
+++ b/src/core/ngx_conf_file.c
@@ -670,20 +670,9 @@
 
     name->len = cycle->root.len + old.len;
 
-    if (cycle->connections) {
-        name->data = ngx_palloc(cycle->pool, name->len + 1);
-        if (name->data == NULL) {
-            return  NGX_ERROR;
-        }
-
-    } else {
-
-        /* the init_cycle */
-
-        name->data = ngx_alloc(name->len + 1, cycle->log);
-        if (name->data == NULL) {
-            return  NGX_ERROR;
-        }
+    name->data = ngx_palloc(cycle->pool, name->len + 1);
+    if (name->data == NULL) {
+        return  NGX_ERROR;
     }
 
     p = ngx_cpymem(name->data, cycle->root.data, cycle->root.len),
diff --git a/src/core/ngx_config.h b/src/core/ngx_config.h
index d924ec5..6078d89 100644
--- a/src/core/ngx_config.h
+++ b/src/core/ngx_config.h
@@ -99,7 +99,8 @@
 #endif
 
 #define ngx_align(d, a)     (((d) + (a - 1)) & ~(a - 1))
-#define ngx_align_ptr(p, a) (u_char *) (((uintptr_t) (p) + (a - 1)) & ~(a - 1))
+#define ngx_align_ptr(p, a)                                                   \
+    (u_char *) (((uintptr_t) (p) + ((uintptr_t) a - 1)) & ~((uintptr_t) a - 1))
 
 
 #define ngx_abort       abort
diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c
index 93b43c4..7560428 100644
--- a/src/core/ngx_connection.c
+++ b/src/core/ngx_connection.c
@@ -722,9 +722,7 @@
         || err == NGX_EPIPE
 #endif
         || err == NGX_ENOTCONN
-#if !(NGX_CRIT_ETIMEDOUT)
         || err == NGX_ETIMEDOUT
-#endif
         || err == NGX_ECONNREFUSED
         || err == NGX_EHOSTUNREACH)
     {
diff --git a/src/core/ngx_core.h b/src/core/ngx_core.h
index 38395cb..46e88df 100644
--- a/src/core/ngx_core.h
+++ b/src/core/ngx_core.h
@@ -42,7 +42,7 @@
 #include <ngx_time.h>
 #include <ngx_socket.h>
 #include <ngx_types.h>
-#include <ngx_shared.h>
+#include <ngx_shmem.h>
 #include <ngx_process.h>
 #include <ngx_user.h>
 #include <ngx_string.h>
diff --git a/src/core/ngx_cycle.c b/src/core/ngx_cycle.c
index e13bcd8..4bff828 100644
--- a/src/core/ngx_cycle.c
+++ b/src/core/ngx_cycle.c
@@ -9,6 +9,7 @@
 #include <ngx_event.h>
 
 
+static void ngx_destroy_cycle_pools(ngx_conf_t *conf);
 static ngx_int_t ngx_cmp_sockaddr(struct sockaddr *sa1, struct sockaddr *sa2);
 static void ngx_clean_old_cycles(ngx_event_t *ev);
 
@@ -40,17 +41,18 @@
 ngx_cycle_t *
 ngx_init_cycle(ngx_cycle_t *old_cycle)
 {
-    void                      *rv;
-    ngx_uint_t                 i, n, failed;
-    ngx_log_t                 *log;
-    ngx_conf_t                 conf;
-    ngx_pool_t                *pool;
-    ngx_cycle_t               *cycle, **old;
-    ngx_list_part_t           *part;
-    ngx_open_file_t           *file;
-    ngx_listening_t           *ls, *nls;
-    ngx_core_conf_t           *ccf;
-    ngx_core_module_t         *module;
+    void               *rv;
+    ngx_uint_t          i, n, failed;
+    ngx_log_t          *log;
+    ngx_conf_t          conf;
+    ngx_pool_t         *pool;
+    ngx_cycle_t        *cycle, **old;
+    ngx_list_part_t    *part;
+    ngx_open_file_t    *file;
+    ngx_listening_t    *ls, *nls;
+    ngx_core_conf_t    *ccf;
+    ngx_core_module_t  *module;
+
 
     log = old_cycle->log;
 
@@ -69,11 +71,20 @@
     cycle->pool = pool;
     cycle->log = log;
     cycle->old_cycle = old_cycle;
-    cycle->conf_file = old_cycle->conf_file;
     cycle->root.len = sizeof(NGX_PREFIX) - 1;
     cycle->root.data = (u_char *) NGX_PREFIX;
 
 
+    cycle->conf_file.len = old_cycle->conf_file.len;
+    cycle->conf_file.data = ngx_palloc(pool, old_cycle->conf_file.len + 1);
+    if (cycle->conf_file.data == NULL) {
+        ngx_destroy_pool(pool);
+        return NULL;
+    }
+    ngx_cpystrn(cycle->conf_file.data, old_cycle->conf_file.data,
+                old_cycle->conf_file.len + 1);
+
+
     n = old_cycle->pathes.nelts ? old_cycle->pathes.nelts : 10;
 
     cycle->pathes.elts = ngx_pcalloc(pool, n * sizeof(ngx_path_t *));
@@ -99,7 +110,7 @@
     }
 
     if (ngx_list_init(&cycle->open_files, pool, n, sizeof(ngx_open_file_t))
-                                                                  == NGX_ERROR)
+        == NGX_ERROR)
     {
         ngx_destroy_pool(pool);
         return NULL;
@@ -168,6 +179,22 @@
         return NULL;
     }
 
+
+#if 0
+    cycle->shm.size = /* STUB */ ngx_pagesize;
+    cycle->shm.log = log;
+
+    if (ngx_shm_alloc(&cycle->shm) != NGX_OK) {
+        ngx_destroy_pool(conf.temp_pool);
+        ngx_destroy_pool(pool);
+        return NULL;
+    }
+
+    cycle->shm_last = cycle->shm.addr;
+    cycle->shm_end = cycle->shm.addr + cycle->shm.size;
+#endif
+
+
     conf.ctx = cycle->conf_ctx;
     conf.cycle = cycle;
     conf.pool = pool;
@@ -180,8 +207,7 @@
 #endif
 
     if (ngx_conf_parse(&conf, &cycle->conf_file) != NGX_CONF_OK) {
-        ngx_destroy_pool(conf.temp_pool);
-        ngx_destroy_pool(pool);
+        ngx_destroy_cycle_pools(&conf);
         return NULL;
     }
 
@@ -203,8 +229,7 @@
             if (module->init_conf(cycle, cycle->conf_ctx[ngx_modules[i]->index])
                 == NGX_CONF_ERROR)
             {
-                ngx_destroy_pool(conf.temp_pool);
-                ngx_destroy_pool(pool);
+                ngx_destroy_cycle_pools(&conf);
                 return NULL;
             }
         }
@@ -397,6 +422,7 @@
         }
     }
 
+
     if (failed) {
 
         /* rollback the new cycle configuration */
@@ -429,8 +455,7 @@
         }
 
         if (ngx_test_config) {
-            ngx_destroy_pool(conf.temp_pool);
-            ngx_destroy_pool(pool);
+            ngx_destroy_cycle_pools(&conf);
             return NULL;
         }
 
@@ -447,8 +472,7 @@
             }
         }
 
-        ngx_destroy_pool(conf.temp_pool);
-        ngx_destroy_pool(pool);
+        ngx_destroy_cycle_pools(&conf);
         return NULL;
     }
 
@@ -533,16 +557,16 @@
 
     ngx_destroy_pool(conf.temp_pool);
 
-    if (old_cycle->connections == NULL) {
-        /* an old cycle is an init cycle */
+    if (ngx_process == NGX_PROCESS_MASTER || ngx_is_init_cycle(old_cycle)) {
+
+        if (old_cycle->shm.addr) {
+            ngx_shm_free(&old_cycle->shm);
+        }
+
         ngx_destroy_pool(old_cycle->pool);
         return cycle;
     }
 
-    if (ngx_process == NGX_PROCESS_MASTER) {
-        ngx_destroy_pool(old_cycle->pool);
-        return cycle;
-    }
 
     if (ngx_temp_pool == NULL) {
         ngx_temp_pool = ngx_create_pool(128, cycle->log);
@@ -586,6 +610,15 @@
 }
 
 
+static void
+ngx_destroy_cycle_pools(ngx_conf_t *conf)
+{
+    ngx_shm_free(&conf->cycle->shm);
+    ngx_destroy_pool(conf->temp_pool);
+    ngx_destroy_pool(conf->pool);
+}
+
+
 static ngx_int_t
 ngx_cmp_sockaddr(struct sockaddr *sa1, struct sockaddr *sa2)
 {
@@ -623,7 +656,7 @@
     ngx_file_t        file;
     ngx_core_conf_t  *ccf, *old_ccf;
 
-    if (!ngx_test_config && old_cycle && old_cycle->conf_ctx == NULL) {
+    if (!ngx_test_config && ngx_is_init_cycle(old_cycle)) {
 
         /*
          * do not create the pid file in the first ngx_init_cycle() call
diff --git a/src/core/ngx_cycle.h b/src/core/ngx_cycle.h
index cbf8c7b..b29cf34 100644
--- a/src/core/ngx_cycle.h
+++ b/src/core/ngx_cycle.h
@@ -32,6 +32,10 @@
     ngx_connection_t         *free_connections;
     ngx_uint_t                free_connection_n;
 
+    ngx_shm_t                 shm;
+    u_char                   *shm_last;
+    u_char                   *shm_end;
+
     ngx_array_t               listening;
     ngx_array_t               pathes;
     ngx_list_t                open_files;
@@ -90,6 +94,9 @@
 } ngx_core_tls_t;
 
 
+#define ngx_is_init_cycle(old)  (old && old->conf_ctx == NULL)
+
+
 ngx_cycle_t *ngx_init_cycle(ngx_cycle_t *old_cycle);
 ngx_int_t ngx_create_pidfile(ngx_cycle_t *cycle, ngx_cycle_t *old_cycle);
 void ngx_delete_pidfile(ngx_cycle_t *cycle);
diff --git a/src/core/ngx_palloc.c b/src/core/ngx_palloc.c
index a0229b2..eb0e86d 100644
--- a/src/core/ngx_palloc.c
+++ b/src/core/ngx_palloc.c
@@ -221,6 +221,46 @@
 }
 
 
+void *
+ngx_shalloc(size_t size)
+{
+    u_char  *p;
+
+    if (size < sizeof(int) || (size & 1)) {
+        p = ngx_cycle->shm_last;
+
+    } else {
+        p = ngx_align_ptr(ngx_cycle->shm_last, NGX_ALIGNMENT);
+    }
+
+    if ((size_t) (ngx_cycle->shm_end - p) >= size) {
+        ngx_cycle->shm_last = p + size;
+        return p;
+    }
+
+    ngx_log_error(NGX_LOG_EMERG, ngx_cycle->log, 0,
+                  "allocation of %uz bytes in shared memory failed, "
+                  "only %uz are available",
+                  size, ngx_cycle->shm_end - ngx_cycle->shm_last);
+
+    return NULL;
+}
+
+
+void *
+ngx_shcalloc(size_t size)
+{
+    void *p;
+
+    p = ngx_shalloc(size);
+    if (p) {
+        ngx_memzero(p, size);
+    }
+
+    return p;
+}
+
+
 ngx_pool_cleanup_t *
 ngx_pool_cleanup_add(ngx_pool_t *p, size_t size)
 {
diff --git a/src/core/ngx_palloc.h b/src/core/ngx_palloc.h
index 2397281..85e77f5 100644
--- a/src/core/ngx_palloc.h
+++ b/src/core/ngx_palloc.h
@@ -71,6 +71,10 @@
 void *ngx_pcalloc(ngx_pool_t *pool, size_t size);
 ngx_int_t ngx_pfree(ngx_pool_t *pool, void *p);
 
+void *ngx_shalloc(size_t size);
+void *ngx_shcalloc(size_t size);
+void ngx_shfree(void *p);
+
 
 ngx_pool_cleanup_t *ngx_pool_cleanup_add(ngx_pool_t *p, size_t size);
 void ngx_pool_cleanup_file(void *data);