Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Core/DB Layer: Fix a memory leak.

  • Loading branch information...
commit 43048afc7e95e895e8d98ebb242692b456e4e7ca 1 parent 19f821d
@Machiavell1 Machiavell1 authored
View
2  src/server/authserver/Main.cpp
@@ -246,8 +246,6 @@ extern int main(int argc, char **argv)
// Initialize connection to the database
bool StartDB()
{
- MySQL::Library_Init();
-
std::string dbstring = ConfigMgr::GetStringDefault("LoginDatabaseInfo", "");
if (dbstring.empty())
{
View
7 src/server/shared/Database/DatabaseWorker.cpp
@@ -34,6 +34,11 @@ int DatabaseWorker::svc()
if (!m_queue)
return -1;
+ //! Since this is called from the worker thread itself, we can ensure
+ //! that thread-specific variables remain in this thread.
+ if (!m_conn->Open())
+ return -1;
+
SQLOperation *request = NULL;
while (1)
{
@@ -47,5 +52,7 @@ int DatabaseWorker::svc()
delete request;
}
+ //! Clean up thread-specific variables
+ m_conn->Close();
return 0;
}
View
5 src/server/shared/Database/DatabaseWorkerPool.h
@@ -53,7 +53,7 @@ class DatabaseWorkerPool
public:
/* Activity state */
DatabaseWorkerPool() :
- m_queue(new ACE_Activation_Queue(new ACE_Message_Queue<ACE_MT_SYNCH>))
+ m_queue(new ACE_Activation_Queue())
{
memset(m_connectionCount, 0, sizeof(m_connectionCount));
m_connections.resize(IDX_SIZE);
@@ -77,7 +77,6 @@ class DatabaseWorkerPool
for (uint8 i = 0; i < async_threads; ++i)
{
T* t = new T(m_queue, m_connectionInfo);
- res &= t->Open();
m_connections[IDX_ASYNC][i] = t;
++m_connectionCount[IDX_ASYNC];
}
@@ -111,7 +110,6 @@ class DatabaseWorkerPool
DatabaseWorker* worker = t->m_worker;
worker->wait();
delete worker;
- t->Close();
}
sLog->outSQLDriver("Asynchronous connections on databasepool '%s' terminated. Proceeding with synchronous connections.", m_connectionInfo.database.c_str());
@@ -125,6 +123,7 @@ class DatabaseWorkerPool
t->Close();
}
+ delete m_queue;
sLog->outSQLDriver("All connections on databasepool %s closed.", m_connectionInfo.database.c_str());
}
View
4 src/server/shared/Database/MySQLConnection.cpp
@@ -68,9 +68,13 @@ MySQLConnection::~MySQLConnection()
}
mysql_close(m_Mysql);
+ MySQL::Thread_End();
Unlock(); /// Unlock while we die, how ironic
}
+//! Can be called synchronously in DatabaseWorkerPool, in which thread-specific variables initialized in the main thread
+//! are deallocated.
+//! Can also be called by worker threads, in which their respective thread-specific variables are deallocated.
void MySQLConnection::Close()
{
/// Only close us if we're not operating
View
2  src/server/worldserver/Master.cpp
@@ -362,8 +362,6 @@ int Master::Run()
/// Initialize connection to the databases
bool Master::_StartDB()
{
- MySQL::Library_Init();
-
sLog->SetLogDB(false);
std::string dbstring;
uint8 async_threads, synch_threads;

1 comment on commit 43048af

@DedaGates

In memory of Leak.
R.I.P 25/03/2012
Dimitro raped and dismembered him...

Please sign in to comment.
Something went wrong with that request. Please try again.