From 461a62e0c85233a714b896c692d6716319ccc9fe Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Sun, 8 May 2011 17:56:52 +0200 Subject: [PATCH] LocalServer crash fix --- cockatrice/src/localserver.cpp | 1 + common/server.cpp | 10 ++++++++++ common/server.h | 1 + common/server_protocolhandler.cpp | 1 + common/server_room.cpp | 13 +++++++++++++ common/server_room.h | 1 + servatrice/src/servatrice.cpp | 1 + 7 files changed, 28 insertions(+) diff --git a/cockatrice/src/localserver.cpp b/cockatrice/src/localserver.cpp index 4cadbdf31..2793a28e2 100644 --- a/cockatrice/src/localserver.cpp +++ b/cockatrice/src/localserver.cpp @@ -10,6 +10,7 @@ LocalServer::LocalServer(QObject *parent) LocalServer::~LocalServer() { + prepareDestroy(); } LocalServerInterface *LocalServer::newConnection() diff --git a/common/server.cpp b/common/server.cpp index 67e1172a7..a7e4c683a 100644 --- a/common/server.cpp +++ b/common/server.cpp @@ -32,8 +32,18 @@ Server::Server(QObject *parent) Server::~Server() { +} + +void Server::prepareDestroy() +{ + QMutexLocker locker(&serverMutex); + while (!clients.isEmpty()) delete clients.takeFirst(); + + QMapIterator roomIterator(rooms); + while (roomIterator.hasNext()) + delete roomIterator.next().value(); } AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString &name, const QString &password) diff --git a/common/server.h b/common/server.h index e401ca806..1c35f5a1b 100644 --- a/common/server.h +++ b/common/server.h @@ -45,6 +45,7 @@ public: virtual QMap getIgnoreList(const QString &name) = 0; virtual bool getUserBanned(Server_ProtocolHandler * /*client*/, const QString & /*userName*/) const { return false; } protected: + void prepareDestroy(); QList clients; QMap users; QMap rooms; diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index 70e8c1eb6..dd5d0dd8f 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -29,6 +29,7 @@ Server_ProtocolHandler::~Server_ProtocolHandler() void Server_ProtocolHandler::prepareDestroy() { QMutexLocker locker(&server->serverMutex); + qDebug("Server_ProtocolHandler::prepareDestroy"); server->removeClient(this); diff --git a/common/server_room.cpp b/common/server_room.cpp index 75aa10edd..b954fa81c 100644 --- a/common/server_room.cpp +++ b/common/server_room.cpp @@ -8,6 +8,19 @@ Server_Room::Server_Room(int _id, const QString &_name, const QString &_descript { } +Server_Room::~Server_Room() +{ + QMutexLocker locker(&roomMutex); + qDebug("Server_Room destructor"); + + const QList gameList = games.values(); + for (int i = 0; i < gameList.size(); ++i) + delete gameList[i]; + games.clear(); + + clear(); +} + Server *Server_Room::getServer() const { return static_cast(parent()); diff --git a/common/server_room.h b/common/server_room.h index e5f4867c4..b99b626f2 100644 --- a/common/server_room.h +++ b/common/server_room.h @@ -29,6 +29,7 @@ private: public: mutable QMutex roomMutex; Server_Room(int _id, const QString &_name, const QString &_description, bool _autoJoin, const QString &_joinMessage, const QStringList &_gameTypes, Server *parent); + ~Server_Room(); int getId() const { return id; } QString getName() const { return name; } QString getDescription() const { return description; } diff --git a/servatrice/src/servatrice.cpp b/servatrice/src/servatrice.cpp index c31b0a441..6346e0e9c 100644 --- a/servatrice/src/servatrice.cpp +++ b/servatrice/src/servatrice.cpp @@ -107,6 +107,7 @@ Servatrice::Servatrice(QSettings *_settings, QObject *parent) Servatrice::~Servatrice() { + prepareDestroy(); } bool Servatrice::openDatabase()