apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Schaefer <joe+gm...@sunstarsys.com>
Subject Re: When to call apr_bucket_alloc_destroy?
Date Fri, 11 Mar 2005 20:16:34 GMT
Joe Schaefer <joe+gmane@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


Mime
View raw message