perl-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geoffrey Young <>
Subject [Fwd: Use of brigade_split...]
Date Fri, 18 Feb 2005 13:35:57 GMT
just in case this is something we do - I haven't checked yet.

the complete thread is there

at at least joe orton agrees there is a problem, so with two guys agreeing
it's probably worth looking into.


-------- Original Message --------
Subject: Use of brigade_split...
Date: Fri, 18 Feb 2005 01:12:52 -0800
From: Paul Querna <>

First, let me say that apr_brigade_split is evil.

It is used in several filters to break up input, or temporarily store
some buckets. The problem is that it allocates a new brigade, commonly
out of the request pool.

This is fine, if you only call it once, but for streaming filters, where
your filter might be called hundreds of times, it will leak a brigade
every time.

This was the cause of the memory 'leak' in PR 33382 (Proxying Windows
Media Player Streams).  With just a quick look in the source, I believe
there is also a bug in the mod_deflate input filter. Consider the code
in mod_deflate.c line 813:

    if (!APR_BRIGADE_EMPTY(ctx->proc_bb)) {
        apr_bucket_brigade *newbb;

        /* May return APR_INCOMPLETE which is fine by us. */
        apr_brigade_partition(ctx->proc_bb, readbytes, &bkt);

        newbb = apr_brigade_split(ctx->proc_bb, bkt);
        APR_BRIGADE_CONCAT(bb, ctx->proc_bb);
        APR_BRIGADE_CONCAT(ctx->proc_bb, newbb);

While this code works, it does not provide any reuse of the bucket
brigade *newbb. The inflate filter will effectively leak one brigade
every time it is called.  To fix it, a brigade should be added to the
filter context, and recycled. Instead of using brigade_split, the
buckets should be moved to this persistent brigade.

I count 11 [1] uses of apr_brigade_split in the trunk source tree.  If
anyone has some spare time, I believe many of them will reveal that they
 have the possibility to leak too.  I will try to investigate them all
sooner or later, but some help on this hunt would be nice :)



To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message