httpd-apreq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joe Schaefer <joe+gm...@sunstarsys.com>
Subject [PATCH] Re: Parsers test eats all the memory
Date Thu, 13 Jan 2005 02:41:00 GMT
Stas Bekman <stas@stason.org> writes:


[...]

>> I'm trying to rewrite the test to use sub-pools, so the memory is
>> freed more often, but it seems that there are some leaks, so even
>> when reducing the test to a very minimum, just a plain
>>   apr_brigade_create(sp, apr_bucket_alloc_create(sp));
>> leaks like crazy. so i'm still looking at it.
>
> This consumes 259MB:

[...]

>              bb = apr_brigade_create(sp, apr_bucket_alloc_create(sp));
>              apr_brigade_destroy(bb);
>
>              apr_pool_destroy(sp);


I see the problem now.  The pool cleanup doesn't free the memory
associated to apr_bucket_alloc_create; it just resets the allocator.
There needs to be an associated apr_bucket_alloc_destroy call (before
the pool is destroyed).


> Unless the leak happens only in the debug-enabled version of pool functions,
> i.e. apr_pool_destroy doesn't free the memory. I suspect that this is the
> case. going to look at the apr source code after dinner.

The reason we don't see this without --enable-pool-debug is because
the created allocator is shared (I think).   Here's a patch that 
should fix the test suite; mod_apreq should be ok, but the cgi
env may need a similar patch.  Please test.


Index: t/parsers.c
===================================================================
--- t/parsers.c	(revision 123167)
+++ t/parsers.c	(working copy)
@@ -176,6 +176,7 @@
 {
     apr_status_t rv;
     apr_size_t i, j;
+    apr_bucket_alloc_t *ba;
 
     for (j = 0; j <= strlen(form_data); ++j) {
         const char *enctype;
@@ -189,7 +190,8 @@
         enctype = apreq_enctype(req->env);
         CuAssertStrEquals(tc, APREQ_MFD_ENCTYPE, enctype);
 
-        bb = apr_brigade_create(p, apr_bucket_alloc_create(p));
+        ba = apr_bucket_alloc_create(p);
+        bb = apr_brigade_create(p, ba);
 
         for (i = 0; i <= strlen(form_data); ++i) {
             const char *val;
@@ -241,10 +243,11 @@
             CuAssertStrEquals(tc, "text/plain", val);
             apr_brigade_cleanup(bb);
         }
-
+        apr_bucket_alloc_destroy(ba);
         apr_pool_clear(p);
     }
 }
+
 static void parse_disable_uploads(CuTest *tc)
 {
     const char *val;
Index: t/testall.c
===================================================================
--- t/testall.c	(revision 123167)
+++ t/testall.c	(working copy)
@@ -66,9 +66,18 @@
     return p;
 }
 
+static apr_status_t bucket_alloc_cleanup(void *data)
+{
+    apr_bucket_alloc_t *ba = data;
+    apr_bucket_alloc_destroy(ba);
+    return APR_SUCCESS;
+}
+
 static apr_bucket_alloc_t *test_bucket_alloc(void *env)
 {
-    return apr_bucket_alloc_create(p);
+    apr_bucket_alloc_t *ba = apr_bucket_alloc_create(p);
+    apr_pool_cleanup_register(p, ba, bucket_alloc_cleanup, NULL);
+    return ba;
 }
 
 static const char *test_header_in(void *env, const char *name)



-- 
Joe Schaefer


Mime
View raw message