]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
lua output: clean up memory at shutdown 1889/head
authorVictor Julien <victor@inliniac.net>
Tue, 1 Mar 2016 11:53:02 +0000 (12:53 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 1 Mar 2016 14:59:25 +0000 (15:59 +0100)
Lua module and submodules we're completely freed at exit, and nor
was the lua_State.

This patch does all the cleanup.

src/output-lua.c
src/runmodes.c

index a8fcb246f7f8e73b89d1dad6e1b970a27d3bc690..4bfe49558440483c58f2ef6fc4b875dec1add4ed 100644 (file)
@@ -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
index 5a9f9762259ddd209835d40cb8953ceaafac2d62..998780d8b4bbdfc7f58229a7584e77095a7a330a 100644 (file)
@@ -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);
             }