diff --git a/rct/Message.cpp b/rct/Message.cpp index 6bfeb60..ac84b3e 100644 --- a/rct/Message.cpp +++ b/rct/Message.cpp @@ -5,6 +5,7 @@ #include "Serializer.h" #include "QuitMessage.h" #include +#include std::mutex Message::sMutex; Map Message::sFactory; @@ -72,6 +73,7 @@ std::shared_ptr Message::create(int version, const char *data, int size } std::lock_guard lock(sMutex); if (!sFactory.contains(ResponseMessage::MessageId)) { + atexit(Message::cleanup); sFactory[ResponseMessage::MessageId] = new MessageCreator(); sFactory[FinishMessage::MessageId] = new MessageCreator(); sFactory[ConnectMessage::MessageId] = new MessageCreator(); @@ -97,7 +99,3 @@ void Message::cleanup() delete it->second; sFactory.clear(); } - -struct Janitor { - ~Janitor() { Message::cleanup(); } -} janitor;