git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Brigade memory lifetime & leaks


On Tue, Jun 5, 2018 at 2:07 PM, Plüm, Rüdiger, Vodafone Group
<ruediger.pluem@xxxxxxxxxxxx> wrote:
>
> The usual approach in many locations is to store the created bucket brigade
> and reuse it. How about the following (untested):
>
> Index: modules/http/http_request.c
> ===================================================================
> --- modules/http/http_request.c (revision 1832516)
> +++ modules/http/http_request.c (working copy)
> @@ -345,6 +345,16 @@
>      return rv;
>  }
>
> +#define RETRIEVE_BRIGADE_FROM_POOL(bb, key, pool, allocator) do { \
> +    apr_pool_userdata_get((void **)&bb, key, pool); \
> +    if (bb == NULL) { \
> +        bb = apr_brigade_create(pool, allocator); \
> +        apr_pool_userdata_setn((const void *)bb, key, NULL, pool); \
> +    } \
> +    else { \
> +        apr_brigade_cleanup(bb); \
> +    } \
> +} while(0)

+1, possibly in a .h so that it can be used elsewhere (e.g.
ap_request_core_filter)?
Though if we were to API-ize it I'd prefer the acquire/release which
would allow to cleanup after use (rather than on reuse).

Regards,
Yann.