From 9272b500572e5ddc91008f06ac3dbe0299b01249 Mon Sep 17 00:00:00 2001 From: Yann Ylavic Date: Thu, 2 Jul 2020 12:15:57 +0000 Subject: [PATCH] mod_proxy_http: follow up to r1879419: clarify poll callback pds/subpool. Comments about why we need a dedicated pfds and its subpool for ap_mpm_register_poll_callback_timeout(). git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1879437 13f79535-47bb-0310-9956-ffa450edef68 --- modules/proxy/mod_proxy_http.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/modules/proxy/mod_proxy_http.c b/modules/proxy/mod_proxy_http.c index e34ab31fca4..6a778bf2293 100644 --- a/modules/proxy/mod_proxy_http.c +++ b/modules/proxy/mod_proxy_http.c @@ -308,6 +308,7 @@ static void proxy_http_async_cb(void *baton) int status; if (req->pfds) { + /* Clear MPM's temporary data */ apr_pool_clear(req->pfds->pool); } @@ -316,16 +317,24 @@ static void proxy_http_async_cb(void *baton) /* Pump both ends until they'd block and then start over again */ status = ap_proxy_tunnel_run(req->tunnel); if (status == HTTP_GATEWAY_TIME_OUT) { - if (req->pfds) { - apr_pollfd_t *async_pfds = (void *)req->pfds->elts; - apr_pollfd_t *tunnel_pfds = (void *)req->tunnel->pfds->elts; - async_pfds[0].reqevents = tunnel_pfds[0].reqevents; - async_pfds[1].reqevents = tunnel_pfds[1].reqevents; - } - else { + if (!req->pfds) { + /* Create the MPM's (req->)pfds off of our tunnel's, and + * overwrite its pool with a subpool since the MPM will use + * that to alloc its own temporary data, which we want to + * clear on the next round (above) to avoid leaks. + */ req->pfds = apr_array_copy(req->p, req->tunnel->pfds); apr_pool_create(&req->pfds->pool, req->p); } + else { + /* Update only reqevents of the MPM's pfds with our tunnel's, + * the rest didn't change. + */ + APR_ARRAY_IDX(req->pfds, 0, apr_pollfd_t).reqevents = + APR_ARRAY_IDX(req->tunnel->pfds, 0, apr_pollfd_t).reqevents; + APR_ARRAY_IDX(req->pfds, 1, apr_pollfd_t).reqevents = + APR_ARRAY_IDX(req->tunnel->pfds, 1, apr_pollfd_t).reqevents; + } status = SUSPENDED; } break; -- 2.47.3