From: Ed Borgoyn Date: Fri, 22 Apr 2016 18:01:15 +0000 (-0400) Subject: Fix two memory leaks, a few build warnings, and removed a remnant #include. X-Git-Tag: 3.0.0-233~432^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=043ff988caed8f785a000401c5ccd45b3f2e17e7;p=thirdparty%2Fsnort3.git Fix two memory leaks, a few build warnings, and removed a remnant #include. --- diff --git a/src/flow/ha.cc b/src/flow/ha.cc index a0f874559..8bd639f2a 100644 --- a/src/flow/ha.cc +++ b/src/flow/ha.cc @@ -205,6 +205,7 @@ static uint8_t write_flow_key(Flow* flow, HAMessage* msg) } } +#ifdef FUTURE // Regardless of the message cursor, extract the key and // return the key length. Position the cursor just after the key. static uint8_t read_flow_key(FlowKey* key, HAMessage* msg) @@ -239,6 +240,7 @@ static uint8_t read_flow_key(FlowKey* key, HAMessage* msg) else return 0; } +#endif static inline uint8_t key_size(Flow* flow) { @@ -357,6 +359,7 @@ void HighAvailability::process_update(Flow* flow, const DAQ_PktHdr_t* pkthdr) DebugMessage(DEBUG_HA,"HighAvailability::process_update()\n"); // Only looking for side channel processing - FIXIT-H + UNUSED(pkthdr); // until we add DAQ communications channel if ( !sc || !flow ) return; diff --git a/src/flow/ha.h b/src/flow/ha.h index f7088299a..286b806ca 100644 --- a/src/flow/ha.h +++ b/src/flow/ha.h @@ -20,8 +20,6 @@ #ifndef HA_H #define HA_H -#include - #include "main/snort_types.h" #include "packet_io/sfdaq.h" #include "side_channel/side_channel.h" @@ -150,7 +148,6 @@ public: private: void receive_handler(SCMessage*); SideChannel* sc = nullptr; - bool enabled = false; }; // Top level management of HighAvailability components. diff --git a/src/flow/ha_module.cc b/src/flow/ha_module.cc index 0d363c7c7..d9ce42c09 100644 --- a/src/flow/ha_module.cc +++ b/src/flow/ha_module.cc @@ -113,6 +113,7 @@ bool HighAvailabilityModule::end(const char* fqn, int idx, SnortConfig*) DebugFormat(DEBUG_HA,"HighAvailabilityModule::end(): %s %d\n", fqn, idx); #else UNUSED(fqn); + UNUSED(idx); #endif if ( config.enabled && !HighAvailabilityManager::instantiate(config.ports,config.daq_channel) ) diff --git a/src/side_channel/side_channel_module.h b/src/side_channel/side_channel_module.h index 4ff161fe0..c0f468f18 100644 --- a/src/side_channel/side_channel_module.h +++ b/src/side_channel/side_channel_module.h @@ -34,7 +34,6 @@ struct SideChannelConfig { PortBitSet* ports = nullptr; - Connector::Direction direction = Connector::CONN_UNDEFINED; SCConnectors connectors; }; diff --git a/src/side_channel/test/side_channel_test.cc b/src/side_channel/test/side_channel_test.cc index 69d4d03e6..455b71b15 100644 --- a/src/side_channel/test/side_channel_test.cc +++ b/src/side_channel/test/side_channel_test.cc @@ -39,12 +39,41 @@ class TestConnector : public Connector Direction get_connector_direction() { return CONN_UNDEFINED; } }; +class ReceiveConnector : public Connector +{ + ConnectorMsgHandle* alloc_message(const uint32_t, const uint8_t**) { return nullptr; } + void discard_message(ConnectorMsgHandle*) { } + bool transmit_message(ConnectorMsgHandle*) { return true; } + ConnectorMsgHandle* receive_message(bool) { return nullptr; } + ConnectorMsg* get_connector_msg(ConnectorMsgHandle*) { return nullptr; } + Direction get_connector_direction() { return CONN_RECEIVE; } +}; + +class TransmitConnector : public Connector +{ + ConnectorMsgHandle* alloc_message(const uint32_t, const uint8_t**) { return nullptr; } + void discard_message(ConnectorMsgHandle*) { } + bool transmit_message(ConnectorMsgHandle*) { return true; } + ConnectorMsgHandle* receive_message(bool) { return nullptr; } + ConnectorMsg* get_connector_msg(ConnectorMsgHandle*) { return nullptr; } + Direction get_connector_direction() { return CONN_TRANSMIT; } +}; + void ConnectorManager::thread_init() { } void ConnectorManager::thread_term() { } Connector* ConnectorManager::get_connector(const std::string connector_name) -{ UNUSED(connector_name); return new TestConnector(); } +{ + if ( connector_name == "U" ) + return new TestConnector(); + else if ( connector_name == "R" ) + return new ReceiveConnector(); + else if ( connector_name == "T" ) + return new TransmitConnector(); + else + return nullptr; +} void show_stats(PegCount*, const PegInfo*, unsigned, const char*) { } @@ -56,6 +85,13 @@ void Debug::print(const char*, int, uint64_t, const char*, ...) { } TEST_GROUP(side_channel) { + void setup() + { + } + + void teardown() + { + } }; TEST(side_channel, test) diff --git a/src/stream/base/stream_base.cc b/src/stream/base/stream_base.cc index 32dcee92b..cd2bd06e9 100644 --- a/src/stream/base/stream_base.cc +++ b/src/stream/base/stream_base.cc @@ -221,6 +221,8 @@ void StreamBase::tterm() flow_con->purge_flows(PktType::UDP); flow_con->purge_flows(PktType::PDU); flow_con->purge_flows(PktType::FILE); + + StreamHAManager::tterm(); } void StreamBase::show(SnortConfig*) diff --git a/src/stream/base/stream_ha.cc b/src/stream/base/stream_ha.cc index 2ae3d8887..80691dbf1 100644 --- a/src/stream/base/stream_ha.cc +++ b/src/stream/base/stream_ha.cc @@ -57,6 +57,11 @@ void StreamHAManager::tinit() ha_client = new StreamHAClient(); } +void StreamHAManager::tterm() +{ + delete ha_client; +} + void StreamHAManager::process_deletion(Flow*) { } diff --git a/src/stream/base/stream_ha.h b/src/stream/base/stream_ha.h index 56a70b0d6..3b9845a64 100644 --- a/src/stream/base/stream_ha.h +++ b/src/stream/base/stream_ha.h @@ -42,6 +42,7 @@ class ProtocolHA { public: ProtocolHA(); + virtual ~ProtocolHA() { } virtual void delete_session(Flow*) { } virtual void create_session(Flow*) { } virtual void deactivate_session(Flow*) { } @@ -54,6 +55,7 @@ class StreamHAManager { public: static void tinit(); + static void tterm(); static void process_deletion(Flow*); static StreamHAClient* ha_client; diff --git a/src/stream/udp/stream_udp.cc b/src/stream/udp/stream_udp.cc index 6be438a7e..e2757ff76 100644 --- a/src/stream/udp/stream_udp.cc +++ b/src/stream/udp/stream_udp.cc @@ -117,6 +117,11 @@ static void udp_tinit() UdpHAManager::tinit(); } +static void udp_tterm() +{ + UdpHAManager::tterm(); +} + static Inspector* udp_ctor(Module* m) { StreamUdpModule* mod = (StreamUdpModule*)m; @@ -149,7 +154,7 @@ static const InspectApi udp_api = nullptr, // init nullptr, // term udp_tinit, // tinit - nullptr, // tterm + udp_tterm, // tterm udp_ctor, udp_dtor, udp_ssn, diff --git a/src/stream/udp/udp_ha.cc b/src/stream/udp/udp_ha.cc index db08c051d..2161a983d 100644 --- a/src/stream/udp/udp_ha.cc +++ b/src/stream/udp/udp_ha.cc @@ -38,3 +38,8 @@ void UdpHAManager::tinit() udp_ha = new UdpHA(); } +void UdpHAManager::tterm() +{ + delete udp_ha; +} + diff --git a/src/stream/udp/udp_ha.h b/src/stream/udp/udp_ha.h index 4df688f95..4e31b62d5 100644 --- a/src/stream/udp/udp_ha.h +++ b/src/stream/udp/udp_ha.h @@ -43,6 +43,7 @@ public: static void process_deletion(Flow* flow) { udp_ha->process_deletion(flow); } static void tinit(); + static void tterm(); static UdpHA* udp_ha; }; #endif