diff --git a/src/Notifier.cc b/src/Notifier.cc index 0554284314..16296f4f59 100644 --- a/src/Notifier.cc +++ b/src/Notifier.cc @@ -62,9 +62,4 @@ void Registry::Terminate() { } } -Modifiable::~Modifiable() { - if ( num_receivers ) - registry.Unregister(this); -} - } // namespace zeek::notifier::detail diff --git a/src/Notifier.h b/src/Notifier.h index 6da7d7c59f..f4c0402fac 100644 --- a/src/Notifier.h +++ b/src/Notifier.h @@ -99,8 +99,6 @@ extern Registry registry; */ class Modifiable { public: - virtual ~Modifiable(); - /** * Calling this method signals to all registered receivers that the * object has been modified. @@ -110,6 +108,17 @@ public: registry.Modified(this); } + /** + * Unregister this instance from the registry. + * + * Classes inheriting from Modifiable are required to call + * this from the destructor explicitly. + */ + void Unregister() { + if ( num_receivers ) + registry.Unregister(this); + } + protected: friend class Registry; diff --git a/src/Val.cc b/src/Val.cc index d34426a0e7..9c5da7e962 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -31,6 +31,7 @@ #include "zeek/IPAddr.h" #include "zeek/IntrusivePtr.h" #include "zeek/NetVar.h" +#include "zeek/Notifier.h" #include "zeek/Overflow.h" #include "zeek/PrefixTable.h" #include "zeek/RE.h" @@ -1712,6 +1713,8 @@ void TableVal::Init(TableTypePtr t, bool ordered) { } TableVal::~TableVal() { + notifier::detail::Modifiable::Unregister(); + if ( timer ) detail::timer_mgr->Cancel(timer); @@ -2952,6 +2955,8 @@ RecordVal::RecordVal(RecordTypePtr t, std::vector> init_vals } RecordVal::~RecordVal() { + notifier::detail::Modifiable::Unregister(); + auto n = record_val.size(); for ( unsigned int i = 0; i < n; ++i ) { @@ -3234,6 +3239,8 @@ VectorVal::VectorVal(VectorTypePtr t, std::vector>* vals) : } VectorVal::~VectorVal() { + notifier::detail::Modifiable::Unregister(); + if ( yield_types ) { int n = yield_types->size(); for ( auto i = 0; i < n; ++i ) {