apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Graham Leggett <minf...@sharp.fm>
Subject Re: question about pool-cleanup order
Date Wed, 09 Dec 2009 16:08:55 GMT
Edgar Frank wrote:

> I've been struggling with pools and reslists for a while now.
> Specifically, I create subpools in a reslist constructor. This
> is documented and examples to work around this exist.
> 
> But what I've been wondering about is, why subpools are always
> cleared before the cleanups are run.
> Can anybody explain this in detail to me? Why aren't subpools
> just handled like normal cleanup functions in terms of order?
> What would be the drawbacks if one would do it that way? (except
> that it would break existing code)

Subpools are allowed to reference memory allocated from the parent pool.
What this means is that you have to clean the subpool before trying to
clean the parent pool, otherwise the subpools might end up containing
dangling pointers to memory allocated from the parent pool.

A concrete example of this is an httpd request, which is created from a
subpool of an httpd connection. The request_rec can safely refer to data
allocated from the connection_rec parent pool, because if the
connection_rec is suddenly cleaned up (think a sudden connection
disconnect), the request_rec will be cleaned first (it is a subpool),
and the connection_rec will be cleaned last.

That said, apr v1.4 offers a apr_pool_pre_cleanup_register() function,
allowing you to register a cleanup that runs before the subpools are
cleared. It may do what you want to do.

Regards,
Graham
--

Mime
View raw message