Skip to content

Commit 826f90e

Browse files
committed
mod_lua: Fix memory handling in output filters.
* modules/lua/mod_lua.c (lua_output_filter_handle): Fix brigade iteration to use constant memory. Submitted by: G.Grandes <guillermo.grandes gmail.com> PR: 69590 Github: closes #517 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1924095 13f79535-47bb-0310-9956-ffa450edef68
1 parent b0dce54 commit 826f90e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

changes-entries/pr69590.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*) mod_lua: Fix memory handling in LuaOutputFilter. PR 69590.
2+
[Guillermo Grandes <guillermo.grandes gmail.com>]

modules/lua/mod_lua.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,14 +472,16 @@ static apr_status_t lua_output_filter_handle(ap_filter_t *f, apr_bucket_brigade
472472
L = ctx->L;
473473
/* While the Lua function is still yielding, pass in buckets to the coroutine */
474474
if (!ctx->broken) {
475-
for (pbktIn = APR_BRIGADE_FIRST(pbbIn);
476-
pbktIn != APR_BRIGADE_SENTINEL(pbbIn);
477-
pbktIn = APR_BUCKET_NEXT(pbktIn))
478-
{
475+
while (!APR_BRIGADE_EMPTY(pbbIn)) {
479476
const char *data;
480477
apr_size_t len;
481478
apr_bucket *pbktOut;
482479

480+
pbktIn = APR_BRIGADE_FIRST(pbbIn);
481+
if (APR_BUCKET_IS_EOS(pbktIn)) {
482+
break;
483+
}
484+
483485
/* read the bucket */
484486
apr_bucket_read(pbktIn,&data,&len,APR_BLOCK_READ);
485487

@@ -513,10 +515,11 @@ static apr_status_t lua_output_filter_handle(ap_filter_t *f, apr_bucket_brigade
513515
lua_tostring(L, -1));
514516
return HTTP_INTERNAL_SERVER_ERROR;
515517
}
518+
apr_bucket_delete(pbktIn);
516519
}
517520
/* If we've safely reached the end, do a final call to Lua to allow for any
518521
finishing moves by the script, such as appending a tail. */
519-
if (APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(pbbIn))) {
522+
if (!APR_BRIGADE_EMPTY(pbbIn) && APR_BUCKET_IS_EOS(APR_BRIGADE_LAST(pbbIn))) {
520523
apr_bucket *pbktEOS;
521524
lua_pushnil(L);
522525
lua_setglobal(L, "bucket");

0 commit comments

Comments
 (0)