41a6c3
diff --git a/modules/http/http_request.c b/modules/http/http_request.c
41a6c3
index c97dc77..9885de4 100644
41a6c3
--- a/modules/http/http_request.c
41a6c3
+++ b/modules/http/http_request.c
41a6c3
@@ -227,11 +227,21 @@ AP_DECLARE(void) ap_die(int type, request_rec *r)
41a6c3
     ap_die_r(type, r, r->status);
41a6c3
 }
41a6c3
 
41a6c3
-static void check_pipeline(conn_rec *c)
41a6c3
+#define RETRIEVE_BRIGADE_FROM_POOL(bb, key, pool, allocator) do {       \
41a6c3
+    apr_pool_userdata_get((void **)&bb, key, pool);                     \
41a6c3
+    if (bb == NULL) {                                                   \
41a6c3
+        bb = apr_brigade_create(pool, allocator);                       \
41a6c3
+        apr_pool_userdata_setn((const void *)bb, key, NULL, pool);      \
41a6c3
+    }                                                                   \
41a6c3
+    else {                                                              \
41a6c3
+        apr_brigade_cleanup(bb);                                        \
41a6c3
+    }                                                                   \
41a6c3
+} while(0)
41a6c3
+
41a6c3
+static void check_pipeline(conn_rec *c, apr_bucket_brigade *bb)
41a6c3
 {
41a6c3
     if (c->keepalive != AP_CONN_CLOSE) {
41a6c3
         apr_status_t rv;
41a6c3
-        apr_bucket_brigade *bb = apr_brigade_create(c->pool, c->bucket_alloc);
41a6c3
 
41a6c3
         rv = ap_get_brigade(c->input_filters, bb, AP_MODE_SPECULATIVE,
41a6c3
                             APR_NONBLOCK_READ, 1);
41a6c3
@@ -245,11 +255,10 @@ static void check_pipeline(conn_rec *c)
41a6c3
         else {
41a6c3
             c->data_in_input_filters = 1;
41a6c3
         }
41a6c3
-        apr_brigade_destroy(bb);
41a6c3
+        apr_brigade_cleanup(bb);
41a6c3
     }
41a6c3
 }
41a6c3
 
41a6c3
-
41a6c3
 AP_DECLARE(void) ap_process_request_after_handler(request_rec *r)
41a6c3
 {
41a6c3
     apr_bucket_brigade *bb;
41a6c3
@@ -260,11 +269,13 @@ AP_DECLARE(void) ap_process_request_after_handler(request_rec *r)
41a6c3
      * this bucket is destroyed, the request will be logged and
41a6c3
      * its pool will be freed
41a6c3
      */
41a6c3
-    bb = apr_brigade_create(r->connection->pool, r->connection->bucket_alloc);
41a6c3
+    RETRIEVE_BRIGADE_FROM_POOL(bb, "ap_process_request_after_handler_brigade",
41a6c3
+                               c->pool, c->bucket_alloc);
41a6c3
     b = ap_bucket_eor_create(r->connection->bucket_alloc, r);
41a6c3
     APR_BRIGADE_INSERT_HEAD(bb, b);
41a6c3
 
41a6c3
     ap_pass_brigade(r->connection->output_filters, bb);
41a6c3
+    apr_brigade_cleanup(bb);
41a6c3
 
41a6c3
     /* From here onward, it is no longer safe to reference r
41a6c3
      * or r->pool, because r->pool may have been destroyed
41a6c3
@@ -273,7 +284,7 @@ AP_DECLARE(void) ap_process_request_after_handler(request_rec *r)
41a6c3
 
41a6c3
     if (c->cs)
41a6c3
         c->cs->state = CONN_STATE_WRITE_COMPLETION;
41a6c3
-    check_pipeline(c);
41a6c3
+    check_pipeline(c, bb);
41a6c3
     AP_PROCESS_REQUEST_RETURN((uintptr_t)r, r->uri, r->status);
41a6c3
     if (ap_extended_status) {
41a6c3
         ap_time_process_request(c->sbh, STOP_PREQUEST);
41a6c3
@@ -363,7 +374,8 @@ void ap_process_request(request_rec *r)
41a6c3
     ap_process_async_request(r);
41a6c3
 
41a6c3
     if (!c->data_in_input_filters) {
41a6c3
-        bb = apr_brigade_create(c->pool, c->bucket_alloc);
41a6c3
+        RETRIEVE_BRIGADE_FROM_POOL(bb, "ap_process_request_after_handler_brigade",
41a6c3
+                                   c->pool, c->bucket_alloc);
41a6c3
         b = apr_bucket_flush_create(c->bucket_alloc);
41a6c3
         APR_BRIGADE_INSERT_HEAD(bb, b);
41a6c3
         rv = ap_pass_brigade(c->output_filters, bb);
41a6c3
@@ -380,6 +392,7 @@ void ap_process_request(request_rec *r)
41a6c3
                           "Timeout while writing data for URI %s to the"
41a6c3
                           " client", r->unparsed_uri);
41a6c3
         }
41a6c3
+        apr_brigade_cleanup(bb);
41a6c3
     }
41a6c3
     if (ap_extended_status) {
41a6c3
         ap_time_process_request(c->sbh, STOP_PREQUEST);