--- mod_manager/node.c.orig	Do. Dez 12 16:35:33 2013
+++ mod_manager/node.c	Mo. Dez 23 09:00:23 2013
@@ -94,7 +94,6 @@
     nodeinfo_t *in = (nodeinfo_t *)*data;
     nodeinfo_t *ou = (nodeinfo_t *)mem;
     if (strcmp(in->mess.JVMRoute, ou->mess.JVMRoute) == 0) {
-        apr_size_t vsize = sizeof(void *);
         /*
          * The node information is made of several pieces:
          * Information from the cluster (nodemess_t).
@@ -106,7 +105,7 @@
         ou->mess.id = id;
         ou->updatetime = apr_time_now();
         ou->offset = sizeof(nodemess_t) + sizeof(apr_time_t) + sizeof(int);
-        ou->offset = ou->offset % vsize ? (((ou->offset / vsize) +1 ) * vsize) : ou->offset;
+        ou->offset = APR_ALIGN_DEFAULT(ou->offset);
         *data = ou;
         return APR_SUCCESS;
     }
@@ -117,7 +116,6 @@
     apr_status_t rv;
     nodeinfo_t *ou;
     int ident;
-    apr_size_t vsize = sizeof(void *);
 
     node->mess.id = 0;
     s->storage->ap_slotmem_lock(s->slotmem);
@@ -142,7 +140,7 @@
 
     /* set of offset to the proxy_worker_stat */
     ou->offset = sizeof(nodemess_t) + sizeof(apr_time_t) + sizeof(int);
-    ou->offset = ou->offset % vsize ? (((ou->offset / vsize) +1 ) * vsize) : ou->offset;
+    ou->offset = APR_ALIGN_DEFAULT(ou->offset);
 
     /* blank the proxy status information */
     memset(&(ou->stat), '\0', SIZEOFSCORE);
--- mod_proxy_cluster/mod_proxy_cluster.c.orig	Sa. Sep  7 19:12:49 2013
+++ mod_proxy_cluster/mod_proxy_cluster.c	Do. Jan  9 09:29:25 2014
@@ -27,6 +27,7 @@
 
 #include "apr_strings.h"
 #include "apr_version.h"
+#include "apr_thread_cond.h"
 
 #include "httpd.h"
 #include "http_config.h"
@@ -78,7 +79,10 @@
 static struct sessionid_storage_method *sessionid_storage = NULL; 
 static struct domain_storage_method *domain_storage = NULL; 
 
+static apr_thread_t *watchdog_thread = NULL;
 static apr_thread_mutex_t *lock = NULL;
+static apr_thread_cond_t *exit_cond = NULL;
+static int watchdog_must_terminate = 0;
 
 static server_rec *main_server = NULL;
 #define CREAT_ALL  0 /* create balancers/workers in all VirtualHost */
@@ -796,8 +800,8 @@
 #else
             balancerinfo_t *balan = read_balancer_name(&balancer->name[11], pool);
             if (balan != NULL) {
-                char *sticky = apr_psprintf(conf->pool, "%s|%s", balan->StickySessionCookie,
-                                                                 balan->StickySessionPath);
+                char *sticky = apr_psprintf(pool, "%s|%s", balan->StickySessionCookie,
+                                                           balan->StickySessionPath);
                 int sticky_force=0;
                 int changed = 0;
                 if (balan->StickySession)
@@ -812,7 +816,7 @@
                     changed = -1;
                 }
                 if (balancer->sticky == NULL || strcmp(sticky, balancer->sticky) != 0) {
-                    balancer->sticky = sticky;
+                    balancer->sticky = apr_pstrdup(conf->pool, sticky);
                     changed = -1;
                 }
                 balancer->timeout =  balan->Timeout;
@@ -2480,6 +2484,7 @@
 }
 static void * APR_THREAD_FUNC proxy_cluster_watchdog_func(apr_thread_t *thd, void *data)
 {
+    apr_status_t rv;
     apr_pool_t *pool;
     apr_sleep(apr_time_make(1, 0)); /* wait before starting */
     for (;;) {
@@ -2491,7 +2496,20 @@
 
         if (!conf)
            break;
-        apr_sleep(apr_time_make(1, 0));
+
+        apr_thread_mutex_lock(lock);
+        if (watchdog_must_terminate) {
+            apr_thread_mutex_unlock(lock);
+            break;
+        }
+        rv = apr_thread_cond_timedwait(exit_cond, lock, apr_time_make(1, 0));
+        apr_thread_mutex_unlock(lock);
+        if (rv == APR_SUCCESS)
+            break; /* If condition variable was signaled, terminate. */
+        if (rv != APR_TIMEUP) {
+            ap_log_error(APLOG_MARK, APLOG_ERR, rv, main_server, "cluster: apr_thread_cond_timedwait() failed");
+        }
+
         apr_pool_create(&pool, conf->pool);
         last = node_storage->worker_nodes_need_update(main_server, pool);
         while (s) {
@@ -2517,11 +2535,42 @@
         if (last)
             node_storage->worker_nodes_are_updated(main_server);
     }
+    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, main_server, "cluster: Watchdog thread exiting cleanly.");
     apr_thread_exit(thd, 0);
     return NULL;
 }
 
 /*
+ * Tell the watchdog thread to exit and wait for it to
+ * complete.
+ */
+static int terminate_watchdog(void *data)
+{
+    apr_status_t rv, trv;
+
+    if (watchdog_thread == NULL)
+        return APR_SUCCESS;
+
+    apr_thread_mutex_lock(lock);
+    watchdog_must_terminate = 1;
+    rv = apr_thread_cond_signal(exit_cond);
+    apr_thread_mutex_unlock(lock);
+    if (rv != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, rv, main_server,
+                    "terminate_watchdog: apr_thread_cond_signal failed");
+        return APR_SUCCESS; /* There isn't a lot we can do about this. */
+    }
+
+    rv = apr_thread_join(&trv, watchdog_thread);
+    if (rv != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_ERR, rv, main_server,
+                    "terminate_watchdog: apr_thread_join failed");
+    }
+
+    return APR_SUCCESS;
+}
+
+/*
  * Create a thread per process to make maintenance task.
  * and the mutex of the node creation.
  */
@@ -2528,7 +2577,6 @@
 static void  proxy_cluster_child_init(apr_pool_t *p, server_rec *s)
 {
     apr_status_t rv;
-    apr_thread_t *wdt;
 
     main_server = s;
 
@@ -2538,12 +2586,19 @@
                     "proxy_cluster_child_init: apr_thread_mutex_create failed");
     }
 
-    rv = apr_thread_create(&wdt, NULL, proxy_cluster_watchdog_func, s, p);
+    rv = apr_thread_cond_create(&exit_cond, p);
     if (rv != APR_SUCCESS) {
         ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, s,
+                    "proxy_cluster_child_init: apr_thread_cond_create failed");
+    }
+
+    rv = apr_thread_create(&watchdog_thread, NULL, proxy_cluster_watchdog_func, s, p);
+    if (rv != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, s,
                     "proxy_cluster_child_init: apr_thread_create failed");
     }
 
+    apr_pool_pre_cleanup_register(p, NULL, terminate_watchdog);
 }
 
 static int proxy_cluster_post_config(apr_pool_t *p, apr_pool_t *plog,
--- mod_slotmem/sharedmem_util.c.orig	Do. Dez 12 15:17:31 2013
+++ mod_slotmem/sharedmem_util.c	Do. Dez 19 16:14:47 2013
@@ -156,9 +156,8 @@
     apr_file_t *fp;
     apr_size_t nbytes;
     apr_status_t rv;
-    apr_size_t vsize = sizeof(void *);
 
-    item_size = item_size % vsize ? (((item_size / vsize) +1 ) * vsize) : item_size; 
+    item_size = APR_ALIGN_DEFAULT(item_size);
     nbytes = item_size * item_num + sizeof(int) * (item_num + 1);
     storename = store_filename(pool, name);
     rv = apr_file_open(&fp, storename,  APR_READ | APR_WRITE, APR_OS_DEFAULT, pool);
@@ -258,13 +257,10 @@
     const char *filename;
     apr_size_t nbytes;
     int i, *ident;
-    apr_size_t vsize = sizeof(void *);
-    apr_size_t dsize = sizeof(desc);
-    apr_size_t tsize = sizeof(int) * (item_num + 1);
+    apr_size_t dsize = APR_ALIGN_DEFAULT(sizeof(desc));
+    apr_size_t tsize = APR_ALIGN_DEFAULT(sizeof(int) * (item_num + 1));
 
-    item_size = item_size % vsize ? (((item_size / vsize) +1 ) * vsize) : item_size; 
-    dsize = dsize % vsize ? (((dsize / vsize) +1 ) * vsize) : dsize; 
-    tsize = tsize % vsize ? (((tsize / vsize) +1 ) * vsize) : tsize;
+    item_size = APR_ALIGN_DEFAULT(item_size);
     nbytes = item_size * item_num + tsize + dsize;
     if (globalpool == NULL)
         return APR_ENOSHMAVAIL;
@@ -399,12 +395,10 @@
     const char *fname;
     const char *filename;
     apr_status_t rv;
-    apr_size_t vsize = sizeof(void *);
-    apr_size_t dsize = sizeof(desc);
+    apr_size_t dsize = APR_ALIGN_DEFAULT(sizeof(desc));
     apr_size_t tsize;
 
-    dsize = dsize % vsize ? (((dsize / vsize) +1 ) * vsize) : dsize; 
-    *item_size = *item_size % vsize ? (((*item_size / vsize) +1 ) * vsize) : *item_size; 
+    *item_size = APR_ALIGN_DEFAULT(*item_size);
 
     if (globalpool == NULL) {
         return APR_ENOSHMAVAIL;
@@ -449,8 +443,7 @@
     ptr = apr_shm_baseaddr_get(res->shm);
     memcpy(&desc, ptr, sizeof(desc));
     ptr = ptr + dsize;
-    tsize = sizeof(int) * (desc.item_num + 1);
-    tsize = tsize % vsize ? (((tsize / vsize) +1 ) * vsize) : tsize; 
+    tsize = APR_ALIGN_DEFAULT(sizeof(int) * (desc.item_num + 1));
 
     /* For the chained slotmem stuff */
     res->name = apr_pstrdup(globalpool, fname);
