]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
fixed action leak
authorRuss Combs <rucombs@cisco.com>
Thu, 21 Aug 2014 19:17:36 +0000 (15:17 -0400)
committerRuss Combs <rucombs@cisco.com>
Thu, 21 Aug 2014 19:17:36 +0000 (15:17 -0400)
ChangeLog
src/managers/action_manager.cc

index b373b3ba51a63f82e99dd89a256845654fcc924a..5f159cabd020bd7b58cefd5b4c58c33b05012f69 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+116
+-- fixed valgrind leak
+-- observed memory corruption on Linux when loading dynamic plugins (not
+fixed)
+-- fixed action leak
+
 115
 -- remove share.h
 -- misc FIXITs
index 934849f549dda30eb773e9a67f885a1c39b14d07..cb67d2ae506f1ecc9ff29f6d19f7a6d03bbd6e10 100644 (file)
@@ -34,23 +34,36 @@ using namespace std;
 #include "log/messages.h"
 #include "actions/act_replace.h"
 
-typedef list<const ActionApi*> AList;
+struct Actor
+{
+    const ActionApi* api;
+    IpsAction* act;
+
+    Actor(const ActionApi* p)
+    { api = p; act = nullptr; };
+};
+
+typedef list<Actor> AList;
 static AList s_actors;
 
 static IpsAction* s_reject = nullptr;
 static THREAD_LOCAL IpsAction* s_action = nullptr;
 
 //-------------------------------------------------------------------------
-// engine plugins
+// action plugins
 //-------------------------------------------------------------------------
 
 void ActionManager::add_plugin(const ActionApi* api)
 {
-    s_actors.push_back(api);
+    Actor a(api);
+    s_actors.push_back(a);
 }
 
 void ActionManager::release_plugins()
 {
+    for ( auto& p : s_actors )
+        p.api->dtor(p.act);
+
     s_actors.clear();
 }
 
@@ -58,18 +71,29 @@ void ActionManager::dump_plugins()
 {
     Dumper d("IPS Actions");
 
-    for ( auto* p : s_actors )
-        d.dump(p->base.name, p->base.version);
+    for ( auto& p : s_actors )
+        d.dump(p.api->base.name, p.api->base.version);
+}
+
+static void store(const ActionApi* api, IpsAction* act)
+{
+    for ( auto& p : s_actors )
+        if ( p.api == api )
+        {
+            assert(!p.act);
+            p.act = act;
+            break;
+        }
 }
 
 //-------------------------------------------------------------------------
 
 RuleType ActionManager::get_action_type(const char* s)
 {
-    for ( auto* p : s_actors )
+    for ( auto& p : s_actors )
     {
-        if ( !strcmp(p->base.name, s) )
-            return p->type;
+        if ( !strcmp(p.api->base.name, s) )
+            return p.api->type;
     }
     return RULE_TYPE__NONE;
 }
@@ -87,33 +111,24 @@ void ActionManager::instantiate(
         ListHead* lh = CreateRuleType(sc, api->base.name, api->type, 0, nullptr);
         assert(lh);
         lh->action = act;
+
+        store(api, act);
     }
 }
 
 void ActionManager::thread_init(SnortConfig*)
 {
-    for ( auto* p : s_actors )
-        if ( p->tinit )
-            p->tinit();
+    for ( auto& p : s_actors )
+        if ( p.api->tinit )
+            p.api->tinit();
 }
 
 void ActionManager::thread_term(SnortConfig*)
 {
-    for ( auto* p : s_actors )
-        if ( p->tterm )
-            p->tterm();
-}
-
-#if 0
-static const ActionApi* get_api(const char* keyword)
-{
-    for ( auto* p : s_actors )
-        if ( !strcasecmp(p->base.name, keyword) )
-            return p;
-
-    return nullptr;
+    for ( auto& p : s_actors )
+        if ( p.api->tterm )
+            p.api->tterm();
 }
-#endif
 
 void ActionManager::execute(Packet* p)
 {