Thank you very much. Is the following too loose:
for (b = APR_BRIGADE_FIRST(bb);
b != APR_BRIGADE_SENTINEL(bb);
b = APR_BUCKET_NEXT(b))
{
if (APR_BUCKET_IS_EOS(b))
{
break;
}
else if (apr_bucket_read(b, &buf, &bytes, APR_BLOCK_READ) ==
APR_SUCCESS)
{
// We have a bucket full of raw data
apr_file_write(f, buf, &bytes);
filesize += bytes;
apr_bucket_delete(b);
}
}
apr_file_close(f);
if (bb != NULL)
{
apr_brigade_cleanup(bb);
}
Also, a last question: when dealing with file buckets, I understand that
heap buckets are created as the file is read. That closely corresponds
with what you say below. So my question is: does this mean there is
more cleanup that has to be done wrt the brigade file->upload, the file
bucket brigade? Sometimes it seems to me like the code above leaks too
-- that may be because of the difference between it and your suggestion
(which I don't really see a significant difference) or because of
something having specifically to do with cleaning up after filebody.
Anyway, thank you!
Eddie
Joe Schaefer wrote:
"Edward L. Abrams" <[EMAIL PROTECTED]> writes:
// dump the values in this brigade:
for (b = APR_BRIGADE_FIRST(bb);
b != APR_BRIGADE_SENTINEL(bb);
b = APR_BUCKET_NEXT(b))
This is the source of your leak.
What you need to do is copy the upload brigade
and iterate over it using something like
while (!APR_BRIGADE_EMPTY(bb)) {
apr_bucket_t *e = APR_BRIGADE_FIRST(bb);
...read from the bucket, do something with data...
apr_bucket_delete(e);
}
ie, destroy the buckets as you read from them.
reading from file buckets tends to convert those buckets
into heap buckets, and unless you delete them as you go,
you wind up copying the entire spool file into RAM.