From 4b8b6ec559a337e10224ec2b6c68273a8b9fab43 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 10 Feb 2020 09:44:36 +0100 Subject: [PATCH 1/6] iosource/Manager: eliminate two std::string copies --- src/iosource/Manager.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/iosource/Manager.cc b/src/iosource/Manager.cc index 1161171743..b6c9b6663c 100644 --- a/src/iosource/Manager.cc +++ b/src/iosource/Manager.cc @@ -324,8 +324,8 @@ static std::pair split_prefix(std::string path) PktSrc* Manager::OpenPktSrc(const std::string& path, bool is_live) { std::pair t = split_prefix(path); - std::string prefix = t.first; - std::string npath = t.second; + const auto& prefix = t.first; + const auto& npath = t.second; // Find the component providing packet sources of the requested prefix. From d1dc70c90f7e75fa9f8798195111671a8c524b1e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 10 Feb 2020 10:26:50 +0100 Subject: [PATCH 2/6] iosource/pcap/Source: remove unused fields `last_hdr`, `last_data` --- src/iosource/pcap/Source.cc | 6 ------ src/iosource/pcap/Source.h | 2 -- 2 files changed, 8 deletions(-) diff --git a/src/iosource/pcap/Source.cc b/src/iosource/pcap/Source.cc index 52d87bd3b8..fc9d5618c5 100644 --- a/src/iosource/pcap/Source.cc +++ b/src/iosource/pcap/Source.cc @@ -27,8 +27,6 @@ PcapSource::PcapSource(const std::string& path, bool is_live) props.is_live = is_live; pd = nullptr; memset(¤t_hdr, 0, sizeof(current_hdr)); - memset(&last_hdr, 0, sizeof(last_hdr)); - last_data = nullptr; } void PcapSource::Open() @@ -46,7 +44,6 @@ void PcapSource::Close() pcap_close(pd); pd = nullptr; - last_data = nullptr; Closed(); @@ -213,7 +210,6 @@ bool PcapSource::ExtractNextPacket(Packet* pkt) return false; } - last_data = data; pkt->Init(props.link_type, ¤t_hdr.ts, current_hdr.caplen, current_hdr.len, data); if ( current_hdr.len == 0 || current_hdr.caplen == 0 ) @@ -222,8 +218,6 @@ bool PcapSource::ExtractNextPacket(Packet* pkt) return false; } - last_hdr = current_hdr; - last_data = data; ++stats.received; stats.bytes_received += current_hdr.len; diff --git a/src/iosource/pcap/Source.h b/src/iosource/pcap/Source.h index fd2fa0ec53..f32071cb99 100644 --- a/src/iosource/pcap/Source.h +++ b/src/iosource/pcap/Source.h @@ -41,8 +41,6 @@ private: pcap_t *pd; struct pcap_pkthdr current_hdr; - struct pcap_pkthdr last_hdr; - const u_char* last_data; }; } From a8da8cb8e262f7f7e682b5bca4f7a5d9376ca2c0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 10 Feb 2020 16:26:19 +0100 Subject: [PATCH 3/6] analyzer/protocol/http: remove unnecessary empty destructor --- src/analyzer/protocol/http/HTTP.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/analyzer/protocol/http/HTTP.cc b/src/analyzer/protocol/http/HTTP.cc index 83349d100a..56359a177e 100644 --- a/src/analyzer/protocol/http/HTTP.cc +++ b/src/analyzer/protocol/http/HTTP.cc @@ -176,7 +176,6 @@ void HTTP_Entity::Deliver(int len, const char* data, int trailing_CRLF) class HTTP_Entity::UncompressedOutput : public analyzer::OutputHandler { public: UncompressedOutput(HTTP_Entity* e) { entity = e; } - virtual ~UncompressedOutput() { } virtual void DeliverStream(int len, const u_char* data, bool orig) { entity->DeliverBodyClear(len, (char*) data, false); From 87d3192d9b7a732f3ec3a9b5e81ad31961186cf6 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 10 Feb 2020 17:34:54 +0100 Subject: [PATCH 4/6] analyzer/Manager: remove unnecessary clear() calls from destructor --- src/analyzer/Manager.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/analyzer/Manager.cc b/src/analyzer/Manager.cc index 189a365263..0bcf690a74 100644 --- a/src/analyzer/Manager.cc +++ b/src/analyzer/Manager.cc @@ -70,9 +70,6 @@ Manager::~Manager() for ( analyzer_map_by_port::const_iterator i = analyzers_by_port_udp.begin(); i != analyzers_by_port_udp.end(); i++ ) delete i->second; - analyzers_by_port_udp.clear(); - analyzers_by_port_tcp.clear(); - // Clean up expected-connection table. while ( conns_by_timeout.size() ) { From 8a74ebf2a97b6ee1f2fe333fb81781ae044537b3 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 10 Feb 2020 22:35:48 +0100 Subject: [PATCH 5/6] analyzer/protocol/smtp: remove unnecessary nullptr check --- src/analyzer/protocol/smtp/SMTP.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/analyzer/protocol/smtp/SMTP.cc b/src/analyzer/protocol/smtp/SMTP.cc index bdc6503ba1..2cd8148357 100644 --- a/src/analyzer/protocol/smtp/SMTP.cc +++ b/src/analyzer/protocol/smtp/SMTP.cc @@ -180,8 +180,7 @@ void SMTP_Analyzer::ProcessLine(int length, const char* line, bool orig) { // Don't know whether it is a command line or // a data line. - if ( line_after_gap ) - delete line_after_gap; + delete line_after_gap; line_after_gap = new BroString((const u_char *) line, length, 1); From cceb8a1b0c7cc2cf3b85e221d50085f1f327220b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 4 Feb 2020 10:44:49 +0100 Subject: [PATCH 6/6] RE: make the RE_Matcher destructor non-virtual Nobody overrides it. --- src/RE.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RE.h b/src/RE.h index f1a2317659..7ff6df112c 100644 --- a/src/RE.h +++ b/src/RE.h @@ -174,12 +174,12 @@ protected: int current_pos; }; -class RE_Matcher { +class RE_Matcher final { public: RE_Matcher(); explicit RE_Matcher(const char* pat); RE_Matcher(const char* exact_pat, const char* anywhere_pat); - virtual ~RE_Matcher(); + ~RE_Matcher(); void AddPat(const char* pat);