Actions
Bug #9078
closed
VJ
VJ
output-lua: deinit error paths leak the Lua state
Bug #9078:
output-lua: deinit error paths leak the Lua state
Affected Versions:
Effort:
Difficulty:
Label:
Description
- Status: present in
main(9b7938aec); code-confirmed - Class: resource leak (whole Lua state) on the output deinit error path
- Component:
src/output-lua.c:874-886(OutputLuaLogDoDeinit)
Description¶
lua_getglobal(luastate, "deinit");
if (lua_type(luastate, -1) != LUA_TFUNCTION) {
SCLogError("no deinit function in script");
return; /* skips LuaReturnState */
}
if (lua_pcall(luastate, 0, 0, 0) != 0) {
SCLogError("couldn't run script 'deinit' function: %s", ...);
return; /* skips LuaReturnState */
}
LuaReturnState(luastate);
LuaLogThreadDeinit() still sets deinit_once = 1 after the call, so the state and its C-side contexts are never closed (no second deinit attempt). The output state is unsandboxed and unlimited, so everything it retained leaks for the process lifetime.
Fix direction¶
Call LuaReturnState(luastate) on both error paths (or restructure to log and fall through to a single close). Optionally NULL lua_ctx->luastate after closing.
Test¶
lua-output-deinit-error: output script with a missing deinit and one with a raising deinit; run with LSAN and assert a clean exit.
JI Updated by Jason Ish about 1 month ago
- Status changed from New to In Review
MR1382
JI Updated by Jason Ish about 1 month ago
- Assignee set to Victor Julien
Actions