You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Joe Schaefer <jo...@sunstarsys.com> on 2005/03/10 18:21:20 UTC

When to call apr_bucket_alloc_destroy?

Given the following sequence:

    apr_pool_create(&p, NULL);
    ba = apr_bucket_alloc_create(p);

    ... create some brigades and buckets using p, ba  ...

Do I need to explicitly invoke apr_bucket_alloc_destroy(ba)
at some point?  If so, I assume that should happen before p 
is cleaned up; do I also need to make sure that all the 
brigades are empty first?  Is it safer to register a pool
cleanup for ba before I use it to create any brigades & buckets?
What's the protocol here?

-- 
Joe Schaefer


Re: When to call apr_bucket_alloc_destroy?

Posted by Cliff Woolley <jw...@virginia.edu>.
> @@ -46,6 +46,13 @@
>      apr_bucket_alloc_t *list = data;
>
>      apr_allocator_free(list->allocator, list->blocks);
> +
> +#if APR_POOL_DEBUG
> +    if (list->pool && list->allocator != apr_pool_allocator_get(list->pool)) {
> +        apr_allocator_destroy(list->allocator);
> +    }
> +#endif
> +
>      return APR_SUCCESS;
>  }


+1, thanks.

Re: When to call apr_bucket_alloc_destroy?

Posted by Joe Schaefer <jo...@sunstarsys.com>.
Joe Schaefer <jo...@sunstarsys.com> writes:

> Given the following sequence:
>
>     apr_pool_create(&p, NULL);
>     ba = apr_bucket_alloc_create(p);
>
>     ... create some brigades and buckets using p, ba  ...
>
> Do I need to explicitly invoke apr_bucket_alloc_destroy(ba)
> at some point?  If so, I assume that should happen before p 
> is cleaned up; do I also need to make sure that all the 
> brigades are empty first?  Is it safer to register a pool
> cleanup for ba before I use it to create any brigades & buckets?
> What's the protocol here?

I think explicitly invoking apr_bucket_alloc_destroy is dangerous
in this situation, but with --enable-pool-debug you wind up leaking
an allocator without the explicit call.  Here's a tested patch which
AFAICT fixes the leak for me.  For a related discusion see 

      http://marc.theaimsgroup.com/?t=110557054800001&r=1&w=2

Index: buckets/apr_buckets_alloc.c
===================================================================
--- buckets/apr_buckets_alloc.c	(revision 157131)
+++ buckets/apr_buckets_alloc.c	(working copy)
@@ -46,6 +46,13 @@
     apr_bucket_alloc_t *list = data;
 
     apr_allocator_free(list->allocator, list->blocks);
+
+#if APR_POOL_DEBUG
+    if (list->pool && list->allocator != apr_pool_allocator_get(list->pool)) {
+        apr_allocator_destroy(list->allocator);
+    }
+#endif
+
     return APR_SUCCESS;
 }


I hope this helps.

-- 
Joe Schaefer