mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Core/DB Layer: Fix a memory leak.
This commit is contained in:
@@ -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())
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user