From e3b8bcdcb5abfdc4cfaf0af0f9633ac15d1f3b69 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 3 Dec 2022 18:21:21 +0200 Subject: [PATCH] Plug a memory leak in EventBus --- source/game/eventbus.cpp | 7 +++++++ source/game/eventbus.h | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) 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: -- 2.43.0