Project

General

Profile

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

Added by Victor Julien 2 months ago. Updated 8 days ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
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.


Subtasks 1 (0 open — 1 closed)

Bug #9328: output-lua: deinit error paths leak the Lua state (8.0.x backport)ClosedVictor JulienActions
Actions

Also available in: PDF Atom