]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: hlua: fix reference leak in hlua_post_init_state()
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 20 Mar 2023 15:29:55 +0000 (16:29 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 5 Apr 2023 06:58:17 +0000 (08:58 +0200)
hlua init function references were not released during
hlua_post_init_state().

Hopefully, this function is only used during startup so the resulting
leak is not a big deal.
Since each init lua function runs precisely once, it is safe to release
the ref as soon as the function is restored on the stack.

This could be backported to every stable versions.
Please note that this commit depends on "MINOR: hlua: add simple hlua reference handling API"

src/hlua.c

index dc9c5f96bc795a3a108062c3236dbf65388d43b2..3962381abd0cb04594832dde6feb0a6af6ec9c69 100644 (file)
@@ -11857,6 +11857,10 @@ int hlua_post_init_state(lua_State *L)
 
        list_for_each_entry(init, &hlua_init_functions[hlua_state_id], l) {
                lua_rawgeti(L, LUA_REGISTRYINDEX, init->function_ref);
+               /* function ref should be released right away since it was pushed
+                * on the stack and will not be used anymore
+                */
+               hlua_unref(L, init->function_ref);
 
 #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM >= 504
                ret = lua_resume(L, L, 0, &nres);