fixed amb1079 - threaded queries with results would crash

This commit is contained in:
David Anderson 2007-10-30 00:09:18 +00:00
parent cc99d6d1fb
commit 408e69c41c
3 changed files with 28 additions and 16 deletions

View File

@ -114,3 +114,4 @@ bool MysqlQuery::ExecuteR(QueryInfo *info, char *error, size_t maxlength)
return info->success; return info->success;
} }

View File

@ -70,7 +70,9 @@ static cell AMX_NATIVE_CALL SQL_ThreadQuery(AMX *amx, cell *params)
if (g_FreeThreads.empty()) if (g_FreeThreads.empty())
{ {
kmThread = new MysqlThread(); kmThread = new MysqlThread();
} else { }
else
{
kmThread = g_FreeThreads.front(); kmThread = g_FreeThreads.front();
g_FreeThreads.pop(); g_FreeThreads.pop();
} }
@ -165,13 +167,17 @@ void MysqlThread::RunThread(IThreadHandle *pHandle)
{ {
m_qrInfo.connect_success = false; m_qrInfo.connect_success = false;
m_qrInfo.query_success = false; m_qrInfo.query_success = false;
} else { }
else
{
m_qrInfo.connect_success = true; m_qrInfo.connect_success = true;
pQuery = pDatabase->PrepareQuery(m_query.c_str()); pQuery = pDatabase->PrepareQuery(m_query.c_str());
if (!pQuery->Execute2(&m_qrInfo.amxinfo.info, m_qrInfo.amxinfo.error, 254)) if (!pQuery->Execute2(&m_qrInfo.amxinfo.info, m_qrInfo.amxinfo.error, 254))
{ {
m_qrInfo.query_success = false; m_qrInfo.query_success = false;
} else { }
else
{
m_qrInfo.query_success = true; m_qrInfo.query_success = true;
} }
} }
@ -184,11 +190,13 @@ void MysqlThread::RunThread(IThreadHandle *pHandle)
if (pQuery) if (pQuery)
{ {
m_qrInfo.amxinfo.pQuery = pQuery; pQuery->FreeHandle();
} else { pQuery = NULL;
}
m_qrInfo.amxinfo.pQuery = NULL;
m_qrInfo.amxinfo.opt_ptr = new char[m_query.size() + 1]; m_qrInfo.amxinfo.opt_ptr = new char[m_query.size() + 1];
strcpy(m_qrInfo.amxinfo.opt_ptr, m_query.c_str()); strcpy(m_qrInfo.amxinfo.opt_ptr, m_query.c_str());
}
if (pDatabase) if (pDatabase)
{ {
@ -228,7 +236,9 @@ void MysqlThread::Execute()
if (m_datalen) if (m_datalen)
{ {
data_addr = MF_PrepareCellArray(m_data, m_datalen); data_addr = MF_PrepareCellArray(m_data, m_datalen);
} else { }
else
{
static cell tmpdata[1] = {0}; static cell tmpdata[1] = {0};
data_addr = MF_PrepareCellArray(tmpdata, 1); data_addr = MF_PrepareCellArray(tmpdata, 1);
} }
@ -236,7 +246,9 @@ void MysqlThread::Execute()
if (!m_qrInfo.connect_success) if (!m_qrInfo.connect_success)
{ {
state = -2; state = -2;
} else if (!m_qrInfo.query_success) { }
else if (!m_qrInfo.query_success)
{
state = -1; state = -1;
} }
float diff = gpGlobals->time - m_qrInfo.queue_time; float diff = gpGlobals->time - m_qrInfo.queue_time;
@ -252,7 +264,9 @@ void MysqlThread::Execute()
data_addr, data_addr,
m_datalen, m_datalen,
c_diff); c_diff);
} else { }
else
{
MF_ExecuteForward(m_fwd, MF_ExecuteForward(m_fwd,
(cell)0, (cell)0,
(cell)hndl, (cell)hndl,
@ -263,11 +277,6 @@ void MysqlThread::Execute()
c_diff); c_diff);
} }
FreeHandle(hndl); FreeHandle(hndl);
if (m_qrInfo.amxinfo.pQuery)
{
m_qrInfo.amxinfo.pQuery->FreeHandle();
m_qrInfo.amxinfo.pQuery = NULL;
}
delete [] m_qrInfo.amxinfo.opt_ptr; delete [] m_qrInfo.amxinfo.opt_ptr;
m_qrInfo.amxinfo.opt_ptr = NULL; m_qrInfo.amxinfo.opt_ptr = NULL;
} }
@ -576,3 +585,4 @@ AMX_NATIVE_INFO g_ThreadSqlNatives[] =
{"SQL_ThreadQuery", SQL_ThreadQuery}, {"SQL_ThreadQuery", SQL_ThreadQuery},
{NULL, NULL}, {NULL, NULL},
}; };

View File

@ -88,3 +88,4 @@ private:
}; };
#endif //_INCLUDE_MYSQL_THREADING_H #endif //_INCLUDE_MYSQL_THREADING_H