From: Mikko Rasa Date: Sat, 3 Dec 2022 16:21:21 +0000 (+0200) Subject: Plug a memory leak in EventBus X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=e3b8bcdcb5abfdc4cfaf0af0f9633ac15d1f3b69;p=libs%2Fgame.git Plug a memory leak in EventBus --- diff --git a/source/game/eventbus.cpp b/source/game/eventbus.cpp index 30fc849..62320df 100644 --- a/source/game/eventbus.cpp +++ b/source/game/eventbus.cpp @@ -2,6 +2,13 @@ namespace Msp::Game { +EventBus::~EventBus() +{ + for(Dispatcher &d: dispatchers) + if(d.dispatcher) + d.deleter(d.dispatcher); +} + unsigned EventBus::get_next_id() { static unsigned next_id = 0; diff --git a/source/game/eventbus.h b/source/game/eventbus.h index a4de18f..b9e6c78 100644 --- a/source/game/eventbus.h +++ b/source/game/eventbus.h @@ -3,6 +3,7 @@ #include #include +#include namespace Msp::Game { @@ -30,7 +31,7 @@ struct EventDispatcher }; -class EventBus +class EventBus: public NonCopyable { private: using DeleteFunc = void(void *); @@ -45,6 +46,10 @@ private: std::vector dispatchers; +public: + ~EventBus(); + +private: static unsigned get_next_id(); public: