Skip to content

Commit

Permalink
Make Message cleanup actually happen
Browse files Browse the repository at this point in the history
  • Loading branch information
jhanssen committed Mar 8, 2015
1 parent 32b09d2 commit cdf706a
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions rct/Message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Serializer.h"
#include "QuitMessage.h"
#include <assert.h>
#include <cstdlib>

std::mutex Message::sMutex;
Map<uint8_t, Message::MessageCreatorBase *> Message::sFactory;
Expand Down Expand Up @@ -72,6 +73,7 @@ std::shared_ptr<Message> Message::create(int version, const char *data, int size
}
std::lock_guard<std::mutex> lock(sMutex);
if (!sFactory.contains(ResponseMessage::MessageId)) {
atexit(Message::cleanup);
sFactory[ResponseMessage::MessageId] = new MessageCreator<ResponseMessage>();
sFactory[FinishMessage::MessageId] = new MessageCreator<FinishMessage>();
sFactory[ConnectMessage::MessageId] = new MessageCreator<ConnectMessage>();
Expand All @@ -97,7 +99,3 @@ void Message::cleanup()
delete it->second;
sFactory.clear();
}

struct Janitor {
~Janitor() { Message::cleanup(); }
} janitor;

0 comments on commit cdf706a

Please sign in to comment.