Re: memory leaking on POST

Joe Schaefer <[email protected]>
Newsgroups gmane.comp.apache.apreq
Message-ID <[email protected]>
"Brian McQueen" <[email protected]> writes:

> What bucket type is SPOOL?  I don't see it as a real bucket type.  I'd
> like to try out the patch here, but I can't duplicate it because I
> don't know what a spool bucket is.

See if this patch to library/util.c solves your leak problem.
It compiles, but it's largely untested:

Index: library/util.c
===================================================================
--- library/util.c	(revision 474179)
+++ library/util.c	(working copy)
@@ -777,11 +777,16 @@
 {
     struct iovec v[APREQ_DEFAULT_NELTS];
     apr_status_t s;
-    apr_bucket *e;
+    apr_bucket *e, *first;
     int n = 0;
     *wlen = 0;
+    apr_bucket_brigade *tmp = apr_brigade_create(bb->p, bb->bucket_alloc);
 
-    for (e = APR_BRIGADE_FIRST(bb); e != APR_BRIGADE_SENTINEL(bb);
+    s = apreq_brigade_copy(tmp, bb);
+    if (s != APR_SUCCESS)
+        return s;
+
+    for (e = APR_BRIGADE_FIRST(tmp); e != APR_BRIGADE_SENTINEL(tmp);
          e = APR_BUCKET_NEXT(e))
     {
         apr_size_t len;
@@ -789,6 +794,9 @@
             s = apreq_fwritev(f, v, &n, &len);
             if (s != APR_SUCCESS)
                 return s;
+            while ((first = APR_BRIGADE_FIRST(tmp)) != e)
+                apr_bucket_delete(first);
+
             *wlen += len;
         }
         s = apr_bucket_read(e, (const char **)&(v[n].iov_base),
@@ -805,6 +813,8 @@
         if (s != APR_SUCCESS)
             return s;
         *wlen += len;
+        while ((first = APR_BRIGADE_FIRST(tmp)) != e)
+            apr_bucket_delete(first);
     }
     return APR_SUCCESS;
 }


-- 
Joe Schaefer
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.