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.
pull/1889/head
Victor Julien 11 years ago
parent ecb79391a0
commit 881fc5500d

@ -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

@ -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);
}

Loading…
Cancel
Save