Blame SOURCES/httpd-2.4.6-r1833014.patch

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