From: Peter Powell Date: Thu, 6 Jun 2019 13:14:09 +0000 (+0100) Subject: Only call events on modules which aren't dying. X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=87bbf574bde2149daed9f9967f33ceae13250b70;p=user%2Fhenk%2Fcode%2Finspircd.git Only call events on modules which aren't dying. --- diff --git a/include/event.h b/include/event.h index 92bb4ffec..b00e44e38 100644 --- a/include/event.h +++ b/include/event.h @@ -122,6 +122,9 @@ class Events::ModuleEventListener : private dynamic_reference_base::CaptureHook prov->subscribers.erase(this); } + /** Retrieves the module which created this listener. */ + const Module* GetModule() const { return prov.creator; } + friend struct ModuleEventProvider::Comp; }; @@ -140,7 +143,9 @@ inline bool Events::ModuleEventProvider::Comp::operator()(Events::ModuleEventLis for (::Events::ModuleEventProvider::SubscriberList::const_iterator _i = _handlers.begin(); _i != _handlers.end(); ++_i) \ { \ listenerclass* _t = static_cast(*_i); \ - _t->func params ; \ + const Module* _m = _t->GetModule(); \ + if (_m && !_m->dying) \ + _t->func params ; \ } \ } while (0); @@ -157,6 +162,9 @@ inline bool Events::ModuleEventProvider::Comp::operator()(Events::ModuleEventLis for (::Events::ModuleEventProvider::SubscriberList::const_iterator _i = _handlers.begin(); _i != _handlers.end(); ++_i) \ { \ listenerclass* _t = static_cast(*_i); \ + const Module* _m = _t->GetModule(); \ + if (!_m || _m->dying) \ + continue; \ result = _t->func params ; \ if (result != MOD_RES_PASSTHRU) \ break; \ diff --git a/include/modules.h b/include/modules.h index 86d9d067d..45d2dd492 100644 --- a/include/modules.h +++ b/include/modules.h @@ -121,7 +121,8 @@ struct ModResult { _next = _i+1; \ try \ { \ - (*_i)->y x ; \ + if (!(*_i)->dying) \ + (*_i)->y x ; \ } \ catch (CoreException& modexcept) \ { \ @@ -144,7 +145,8 @@ do { \ _next = _i+1; \ try \ { \ - v = (*_i)->n args; + if (!(*_i)->dying) \ + v = (*_i)->n args; #define WHILE_EACH_HOOK(n) \ } \