apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mladen Turk <mt...@apache.org>
Subject Re: reslists and sub-pools
Date Sat, 23 Dec 2006 07:46:27 GMT
Chris Darroch wrote:
> 
>    But, before the cleanup function runs, apr_pool_destroy() will
> have recursively called itself on all the sub-pools of the reslist's
> pool, including all the sub-pools created by the constructor function.
> Thus when the reslist's cleanup function runs and calls the destructor
> on a resource, the resource's sub-pool and opaque structure have
> been freed; the destructor will issue a second call to apr_pool_destroy()
> on the sub-pool and likely cause the program to crash.
>

I already proposed a solution to this problem few months ago.
IMO the solution is to have two cleanup callback lists and an
api that could mark the callback as pre-subpool-destroy.

So instead having:
apr_pool_destroy/clear {
   destroy_all_subpools
   run_cleanup_callbacks
}

we would have:
apr_pool_destroy/clear {
   run_pred_cleanup_callbacks
   destroy_all_subpools
   run_post_cleanup_callbacks
}

This way when registering the callback you would have a chance
to make sure that any desired callback would be called before
any sub-pool is destroyed.
In case the cleanup callback destroys its pool (common for
suppressing memory leaks) that pool would be removed from the
parent list of pools before calling subpool destroy, and
there will be no double free issues.

Regards,
Mladen.

Mime
View raw message