From cb4eaf762c967aaede75a5da8ace06eca508f82e Mon Sep 17 00:00:00 2001 From: Matthias Vallentin Date: Tue, 15 Apr 2014 12:36:57 +0200 Subject: [PATCH 1/2] Fix bug when clearing Bloom filter contents. This patch fixes a bug that occurred when calling the BiF bloomfilter_clear, which used to not only clear the underlying bit vector but also set its size to zero. As a result, subsequent element access or computations using the bit vector size caused erroneous behavior. Reported by @colonelxc. --- src/probabilistic/BloomFilter.cc | 4 ++-- src/probabilistic/CounterVector.cc | 4 ++-- src/probabilistic/CounterVector.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/probabilistic/BloomFilter.cc b/src/probabilistic/BloomFilter.cc index f6e4017626..ef671268b9 100644 --- a/src/probabilistic/BloomFilter.cc +++ b/src/probabilistic/BloomFilter.cc @@ -72,7 +72,7 @@ bool BasicBloomFilter::Empty() const void BasicBloomFilter::Clear() { - bits->Clear(); + bits->Reset(); } bool BasicBloomFilter::Merge(const BloomFilter* other) @@ -190,7 +190,7 @@ bool CountingBloomFilter::Empty() const void CountingBloomFilter::Clear() { - cells->Clear(); + cells->Reset(); } bool CountingBloomFilter::Merge(const BloomFilter* other) diff --git a/src/probabilistic/CounterVector.cc b/src/probabilistic/CounterVector.cc index 317a28d851..8608015422 100644 --- a/src/probabilistic/CounterVector.cc +++ b/src/probabilistic/CounterVector.cc @@ -75,9 +75,9 @@ bool CounterVector::AllZero() const return bits->AllZero(); } -void CounterVector::Clear() +void CounterVector::Reset() { - bits->Clear(); + bits->Reset(); } CounterVector::count_type CounterVector::Count(size_type cell) const diff --git a/src/probabilistic/CounterVector.h b/src/probabilistic/CounterVector.h index d3efd1aa31..247a646eb1 100644 --- a/src/probabilistic/CounterVector.h +++ b/src/probabilistic/CounterVector.h @@ -86,7 +86,7 @@ public: /** * Sets all counters to 0. */ - void Clear(); + void Reset(); /** * Retrieves the number of cells in the storage. From c9b40f1ca7bdbf9c0cb799477e695b93fcf3ba04 Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Tue, 15 Apr 2014 16:36:47 -0500 Subject: [PATCH 2/2] Change how input/logging threads set their name. Setting the thread name on every heartbeat uses a mild amount of cycles and there's not much benefit to doing it there to get the additional info regarding the number of processed messages since thread names usually get truncated to 16 characters and omit that part anyway. --- src/input/ReaderBackend.cc | 2 ++ src/logging/WriterBackend.cc | 1 + src/threading/MsgThread.cc | 9 --------- src/threading/MsgThread.h | 2 +- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/input/ReaderBackend.cc b/src/input/ReaderBackend.cc index abf369dd54..4c7540609c 100644 --- a/src/input/ReaderBackend.cc +++ b/src/input/ReaderBackend.cc @@ -215,6 +215,8 @@ bool ReaderBackend::Init(const int arg_num_fields, if ( Failed() ) return true; + SetOSName(Fmt("bro: %s", Name())); + num_fields = arg_num_fields; fields = arg_fields; diff --git a/src/logging/WriterBackend.cc b/src/logging/WriterBackend.cc index 5e4230c8e3..35d3137c76 100644 --- a/src/logging/WriterBackend.cc +++ b/src/logging/WriterBackend.cc @@ -180,6 +180,7 @@ void WriterBackend::DisableFrontend() bool WriterBackend::Init(int arg_num_fields, const Field* const* arg_fields) { + SetOSName(Fmt("bro: %s", Name())); num_fields = arg_num_fields; fields = arg_fields; diff --git a/src/threading/MsgThread.cc b/src/threading/MsgThread.cc index c713f65986..cf1facbba5 100644 --- a/src/threading/MsgThread.cc +++ b/src/threading/MsgThread.cc @@ -254,15 +254,6 @@ void MsgThread::Heartbeat() SendIn(new HeartbeatMessage(this, network_time, current_time())); } -void MsgThread::HeartbeatInChild() - { - string n = Fmt("bro: %s (%" PRIu64 "/%" PRIu64 ")", Name(), - cnt_sent_in - queue_in.Size(), - cnt_sent_out - queue_out.Size()); - - SetOSName(n.c_str()); - } - void MsgThread::Finished() { child_finished = true; diff --git a/src/threading/MsgThread.h b/src/threading/MsgThread.h index c5ba5b676f..e0a6f6dc01 100644 --- a/src/threading/MsgThread.h +++ b/src/threading/MsgThread.h @@ -199,7 +199,7 @@ protected: /** Internal heartbeat processing. Called from child. */ - void HeartbeatInChild(); + void HeartbeatInChild() {} /** Returns true if a child command has reported a failure. In that case, we'll * be in the process of killing this thread and no further activity