From 83e2e3666a296ec3766fd92980fae4a74edecb89 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Mon, 4 Jul 2011 17:14:48 +0200 Subject: [PATCH] server memory leak fixed --- common/server_protocolhandler.cpp | 1 + servatrice/src/main.cpp | 5 +++-- servatrice/src/servatrice.cpp | 11 +++++++---- servatrice/src/serversocketinterface.cpp | 1 + 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index 9c752e8a..5e4ba775 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -405,6 +405,7 @@ ResponseCode Server_ProtocolHandler::cmdJoinRoom(Command_JoinRoom *cmd, CommandC if (!r) return RespNameNotFound; + QMutexLocker serverLocker(&server->serverMutex); QMutexLocker roomLocker(&r->roomMutex); r->addClient(this); rooms.insert(r->getId(), r); diff --git a/servatrice/src/main.cpp b/servatrice/src/main.cpp index 6c16c965..247111be 100644 --- a/servatrice/src/main.cpp +++ b/servatrice/src/main.cpp @@ -129,8 +129,8 @@ int main(int argc, char *argv[]) if (testRandom) testRNG(); - Servatrice server(settings); - QObject::connect(&server, SIGNAL(destroyed()), &app, SLOT(quit()), Qt::QueuedConnection); + Servatrice *server = new Servatrice(settings); + QObject::connect(server, SIGNAL(destroyed()), &app, SLOT(quit()), Qt::QueuedConnection); std::cerr << "-------------------------" << std::endl; std::cerr << "Server initialized." << std::endl; @@ -142,6 +142,7 @@ int main(int argc, char *argv[]) delete rng; delete settings; + delete loggerThread; return retval; } diff --git a/servatrice/src/servatrice.cpp b/servatrice/src/servatrice.cpp index 1bb126e5..a19475c1 100644 --- a/servatrice/src/servatrice.cpp +++ b/servatrice/src/servatrice.cpp @@ -66,7 +66,7 @@ Servatrice::Servatrice(QSettings *_settings, QObject *parent) } bool threaded = settings->value("server/threaded", false).toInt(); - tcpServer = new Servatrice_TcpServer(this, threaded); + tcpServer = new Servatrice_TcpServer(this, threaded, this); int port = settings->value("server/port", 4747).toInt(); qDebug() << "Starting server on port" << port; if (tcpServer->listen(QHostAddress::Any, port)) @@ -364,17 +364,20 @@ void Servatrice::updateLoginMessage() void Servatrice::statusUpdate() { - QMutexLocker locker(&dbMutex); + const int uc = getUsersCount(); // for correct mutex locking order + const int gc = getGamesCount(); + uptime += statusUpdateClock->interval() / 1000; + QMutexLocker locker(&dbMutex); checkSql(); QSqlQuery query; query.prepare("insert into " + dbPrefix + "_uptime (id_server, timest, uptime, users_count, games_count) values(:id, NOW(), :uptime, :users_count, :games_count)"); query.bindValue(":id", serverId); query.bindValue(":uptime", uptime); - query.bindValue(":users_count", getUsersCount()); - query.bindValue(":games_count", getGamesCount()); + query.bindValue(":users_count", uc); + query.bindValue(":games_count", gc); execSqlQuery(query); } diff --git a/servatrice/src/serversocketinterface.cpp b/servatrice/src/serversocketinterface.cpp index 895fcee2..1e83693e 100644 --- a/servatrice/src/serversocketinterface.cpp +++ b/servatrice/src/serversocketinterface.cpp @@ -69,6 +69,7 @@ ServerSocketInterface::~ServerSocketInterface() delete xmlReader; delete socket; socket = 0; + delete topLevelItem; } void ServerSocketInterface::processProtocolItem(ProtocolItem *item)