]> granicus.if.org Git - apache/commitdiff
core_output_filter: use the current input brigade's pool for the "more"
authorGreg Ames <gregames@apache.org>
Wed, 13 Nov 2002 15:07:35 +0000 (15:07 +0000)
committerGreg Ames <gregames@apache.org>
Wed, 13 Nov 2002 15:07:35 +0000 (15:07 +0000)
brigade when we defer network writes due to small data + keepalives.  This
prevents leaking resources in the "more" brigade until the end of the
connection.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@97503 13f79535-47bb-0310-9956-ffa450edef68

server/core.c

index ebd94f26e767162fa5af7f08359bb8a58546bd9f..ed04d5c78580f5df1a83f07915b251a5fc1df28c 100644 (file)
@@ -3670,6 +3670,7 @@ static apr_status_t core_output_filter(ap_filter_t *f, apr_bucket_brigade *b)
     core_net_rec *net = f->ctx;
     core_output_filter_ctx_t *ctx = net->out_ctx;
     apr_read_type_e eblock = APR_NONBLOCK_READ;
+    apr_pool_t *input_pool = b->p;
 
     if (ctx == NULL) {
         ctx = apr_pcalloc(c->pool, sizeof(*ctx));
@@ -3998,35 +3999,31 @@ static apr_status_t core_output_filter(ap_filter_t *f, apr_bucket_brigade *b)
         }
 
         apr_brigade_destroy(b);
-
+        
         /* drive cleanups for resources which were set aside 
          * this may occur before or after termination of the request which
          * created the resource
          */
         if (ctx->deferred_write_pool) {
-            if (more) {
+            if (more && more->p == ctx->deferred_write_pool) {
+                /* "more" belongs to the deferred_write_pool,
+                 * which is about to be cleared.
+                 */
                 if (APR_BRIGADE_EMPTY(more)) {
-                    /* the usual case - prevent the next loop iteration
-                     * from referencing a brigade which lives in a
-                     * cleared pool
-                     */
                     more = NULL;
                 }
                 else {
-                    /* change the lifetime of "more" to the connection's
-                     * lifetime
-                     *
-                     * XXX a shorter lifetime would be better for long-running
-                     * keep-alive connections...might be able to use the
-                     * input brigade's pool
+                    /* uh oh... change more's lifetime 
+                     * to the input brigade's lifetime 
                      */
                     apr_bucket_brigade *tmp_more = more;
                     more = NULL;
-                    ap_save_brigade(f, &more, &tmp_more, c->pool);
+                    ap_save_brigade(f, &more, &tmp_more, input_pool);
                 }
             }
             apr_pool_clear(ctx->deferred_write_pool);  
         }
+
         if (rv != APR_SUCCESS) {
             ap_log_error(APLOG_MARK, APLOG_INFO, rv, c->base_server,
                          "core_output_filter: writing data to the network");