From: Russ Combs (rucombs) Date: Wed, 9 Mar 2016 21:01:07 +0000 (-0500) Subject: Merge pull request #328 in SNORT/snort3 from ~JOCORNET/snort3:zhash_minor_fixes to... X-Git-Tag: 3.0.0-233~545 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7bf4fc0e9d4a96d0edf7cf217a31c15f79436614;p=thirdparty%2Fsnort3.git Merge pull request #328 in SNORT/snort3 from ~JOCORNET/snort3:zhash_minor_fixes to master Squashed commit of the following: commit fb5ecd2ba839dee450458176894dfbb2e7f4ff7e Author: Joel Cornett Date: Wed Mar 9 13:52:24 2016 -0500 removed unneeded includes commit eab1f91b40f11ccf540f0e4d3e42aac55dc67a40 Author: Joel Cornett Date: Wed Mar 9 13:50:07 2016 -0500 minor zhash fixes --- diff --git a/src/hash/zhash.cc b/src/hash/zhash.cc index 21ef1fe85..7c88d1859 100644 --- a/src/hash/zhash.cc +++ b/src/hash/zhash.cc @@ -19,13 +19,12 @@ // zhash is based on sfxhash - see sfxhash.cc for details +#include "zhash.h" + #include #include -#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( + ::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; } diff --git a/src/hash/zhash.h b/src/hash/zhash.h index 239192618..6330ad0c1 100644 --- a/src/hash/zhash.h +++ b/src/hash/zhash.h @@ -20,6 +20,8 @@ #ifndef ZHASH_H #define ZHASH_H +#include + struct SFHASHFCN; struct ZHashNode;