From: Victor Julien Date: Tue, 1 Mar 2016 11:53:02 +0000 (+0100) Subject: lua output: clean up memory at shutdown X-Git-Tag: suricata-3.0.1RC1~95 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1889%2Fhead;p=thirdparty%2Fsuricata.git lua output: clean up memory at shutdown Lua module and submodules we're completely freed at exit, and nor was the lua_State. This patch does all the cleanup. --- diff --git a/src/output-lua.c b/src/output-lua.c index a8fcb246f7..4bfe495584 100644 --- a/src/output-lua.c +++ b/src/output-lua.c @@ -800,6 +800,12 @@ error: return NULL; } +static void LogLuaSubFree(OutputCtx *oc) { + if (oc->data) + SCFree(oc->data); + SCFree(oc); +} + /** \brief initialize output for a script instance * * Runs script 'setup' function. @@ -841,7 +847,7 @@ static OutputCtx *OutputLuaLogInitSub(ConfNode *conf, OutputCtx *parent_ctx) SCLogDebug("lua_ctx %p", lua_ctx); output_ctx->data = lua_ctx; - output_ctx->DeInit = NULL; + output_ctx->DeInit = LogLuaSubFree; return output_ctx; error: @@ -851,10 +857,16 @@ error: return NULL; } -static void LogLuaMasterFree(OutputCtx *oc) { - BUG_ON(oc == NULL); +static void LogLuaMasterFree(OutputCtx *oc) +{ if (oc->data) SCFree(oc->data); + + OutputModule *om, *tom; + TAILQ_FOREACH_SAFE(om, &oc->submodules, entries, tom) { + SCFree(om); + } + SCFree(oc); } /** \internal @@ -995,6 +1007,7 @@ static void OutputLuaLogDoDeinit(LogLuaCtx *lua_ctx) SCLogError(SC_ERR_LUA_ERROR, "couldn't run script 'deinit' function: %s", lua_tostring(luastate, -1)); return; } + lua_close(luastate); } /** \internal diff --git a/src/runmodes.c b/src/runmodes.c index 5a9f976225..998780d8b4 100644 --- a/src/runmodes.c +++ b/src/runmodes.c @@ -819,6 +819,10 @@ void RunModeInitializeOutputs(void) } else if (strcmp(output->val, "lua") == 0) { SCLogDebug("handle lua"); + OutputModule *lua_module = OutputGetModuleByConfName(output->val); + BUG_ON(lua_module == NULL); + AddOutputToFreeList(lua_module, output_ctx); + ConfNode *scripts = ConfNodeLookupChild(output_config, "scripts"); BUG_ON(scripts == NULL); //TODO @@ -843,6 +847,7 @@ void RunModeInitializeOutputs(void) continue; } + AddOutputToFreeList(m, sub_output_ctx); SetupOutput(m->name, m, sub_output_ctx); }