From f9d993ebaff8352431dac32a7f4033d33f239c2e Mon Sep 17 00:00:00 2001 From: Greg Ames Date: Wed, 13 Nov 2002 15:07:35 +0000 Subject: [PATCH] core_output_filter: use the current input brigade's pool for the "more" 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 | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/server/core.c b/server/core.c index ebd94f26e7..ed04d5c785 100644 --- a/server/core.c +++ b/server/core.c @@ -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"); -- 2.50.1