From: Aurelien DARRAGON Date: Mon, 13 Mar 2023 13:09:21 +0000 (+0100) Subject: BUG/MINOR: hlua: fix reference leak in core.register_task() X-Git-Tag: v2.8-dev7~49 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=be58d6683c2d46732ea21eb55c4353a4e0c257a3;p=thirdparty%2Fhaproxy.git BUG/MINOR: hlua: fix reference leak in core.register_task() In core.register_task(): we take a reference to the function passed as argument in order to push it in the new coroutine substack. However, once pushed in the substack: the reference is not useful anymore and should be cleared. Currently, this is not the case in hlua_register_task(). Explicitly dropping the reference once the function is pushed to the coroutine's stack to prevent any reference leak (which could contribute to resource shortage) This may be backported to every stable versions. Please note that this commit depends on "MINOR: hlua: add simple hlua reference handling API" --- diff --git a/src/hlua.c b/src/hlua.c index 355060886c..dc9c5f96bc 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -8719,6 +8719,9 @@ static int hlua_register_task(lua_State *L) /* Restore the function in the stack. */ lua_rawgeti(hlua->T, LUA_REGISTRYINDEX, ref); + /* function ref not needed anymore since it was pushed to the substack */ + hlua_unref(L, ref); + hlua->nargs = 0; /* Schedule task. */