]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #328 in SNORT/snort3 from ~JOCORNET/snort3:zhash_minor_fixes to...
authorRuss Combs (rucombs) <rucombs@cisco.com>
Wed, 9 Mar 2016 21:01:07 +0000 (16:01 -0500)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Wed, 9 Mar 2016 21:01:07 +0000 (16:01 -0500)
Squashed commit of the following:

commit fb5ecd2ba839dee450458176894dfbb2e7f4ff7e
Author: Joel Cornett <joel.cornett@gmail.com>
Date:   Wed Mar 9 13:52:24 2016 -0500

    removed unneeded includes

commit eab1f91b40f11ccf540f0e4d3e42aac55dc67a40
Author: Joel Cornett <joel.cornett@gmail.com>
Date:   Wed Mar 9 13:50:07 2016 -0500

    minor zhash fixes

src/hash/zhash.cc
src/hash/zhash.h

index 21ef1fe855e05f56da811bbd96809bf9d8d11cad..7c88d1859e8c22036aeabbbc7dc12c19d7283be9 100644 (file)
 
 // zhash is based on sfxhash - see sfxhash.cc for details
 
+#include "zhash.h"
+
 #include <assert.h>
 #include <stdlib.h>
 
-#include "zhash.h"
 #include "sfhashfcn.h"
-#include "main/snort_types.h"
-#include "main/snort_debug.h"
 #include "utils/util.h"
 
 //-------------------------------------------------------------------------
@@ -46,6 +45,18 @@ struct ZHashNode
     void* data = nullptr;
 };
 
+static inline ZHashNode* s_node_alloc(int keysize)
+{
+    auto node = static_cast<ZHashNode*>(
+        ::operator new(sizeof(ZHashNode) + keysize));
+
+    memset(node, 0, sizeof(ZHashNode));
+    return node;
+}
+
+static inline void s_node_free(ZHashNode* node)
+{ ::operator delete(node); }
+
 void ZHash::delete_free_list()
 {
     if ( !fhead )
@@ -56,7 +67,7 @@ void ZHash::delete_free_list()
     while ( cur )
     {
         fhead = cur->gnext;
-        free(cur);
+        s_node_free(cur);
         cur = fhead;
     }
 }
@@ -249,10 +260,7 @@ ZHash::ZHash(int rows, int keysz)
     }
 
     /* Allocate the array of node ptrs */
-    table = new ZHashNode*[rows];
-
-    for ( int i = 0; i < rows; ++i )
-        table[i] = nullptr;
+    table = new ZHashNode*[rows]();
 
     keysize = keysz;
     nrows = rows;
@@ -275,7 +283,7 @@ ZHash::~ZHash()
             {
                 ZHashNode* onode = node;
                 node = node->next;
-                free(onode);
+                s_node_free(onode);
             }
         }
         delete[] table;
@@ -285,8 +293,7 @@ ZHash::~ZHash()
 
 void* ZHash::push(void* p)
 {
-    ZHashNode* node =
-        (ZHashNode*)SnortAlloc(sizeof(ZHashNode) + keysize);
+    auto node = s_node_alloc(keysize);
 
     node->key = (char*)node + sizeof(ZHashNode);
     node->data = p;
@@ -303,7 +310,7 @@ void* ZHash::pop()
         return nullptr;
 
     void* pv = node->data;
-    free(node);
+    s_node_free(node);
 
     return pv;
 }
index 23919261813a2db74f24a7c72aff7b6317b340a5..6330ad0c178b5cafd06aa8e02e0fbbddbc222dd9 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef ZHASH_H
 #define ZHASH_H
 
+#include <cstddef>
+
 struct SFHASHFCN;
 struct ZHashNode;