]> git.tdb.fi Git - libs/game.git/commitdiff
Plug a memory leak in EventBus
authorMikko Rasa <tdb@tdb.fi>
Sat, 3 Dec 2022 16:21:21 +0000 (18:21 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 4 Dec 2022 13:31:26 +0000 (15:31 +0200)
source/game/eventbus.cpp
source/game/eventbus.h

index 30fc849705b11c1809a4e09bedab7a857ea6e827..62320df9690c312c6062cd1d785da8d439ff560a 100644 (file)
@@ -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;
index a4de18f2bb24c699fb73aea61794b73578cdba77..b9e6c7890c77f5a56cb83f83cfd20c95c08a57c3 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <functional>
 #include <vector>
+#include <msp/core/noncopyable.h>
 
 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<Dispatcher> dispatchers;
 
+public:
+       ~EventBus();
+
+private:
        static unsigned get_next_id();
 
 public: