fixed memory leaks caused by using a CVector instead of a CList
This commit is contained in:
parent
994e41d7cf
commit
67b13237d6
@ -45,11 +45,9 @@ CForward::CForward(const char *name, ForwardExecType et, int numParams, const Fo
|
||||
{
|
||||
if ((*iter).isValid() && amx_FindPublic((*iter).getAMX(), name, &func) == AMX_ERR_NONE)
|
||||
{
|
||||
tmp = new AMXForward;
|
||||
if (!tmp)
|
||||
return; // :TODO: Better error report!!!
|
||||
tmp->pPlugin = &(*iter);
|
||||
tmp->func = func;
|
||||
AMXForward tmp;
|
||||
tmp.pPlugin = &(*iter);
|
||||
tmp.func = func;
|
||||
m_Funcs.push_back(tmp);
|
||||
}
|
||||
}
|
||||
@ -66,11 +64,11 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
|
||||
|
||||
unsigned int id = 0;
|
||||
|
||||
CVector<AMXForward *>::iterator iter;
|
||||
AMXForwardList::iterator iter;
|
||||
|
||||
for (iter = m_Funcs.begin(); iter != m_Funcs.end(); iter++)
|
||||
{
|
||||
if ((*iter)->pPlugin->isExecutable((*iter)->func))
|
||||
if (iter->pPlugin->isExecutable(iter->func))
|
||||
{
|
||||
// handle strings & arrays
|
||||
int i;
|
||||
@ -79,7 +77,7 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
|
||||
if (m_ParamTypes[i] == FP_STRING || m_ParamTypes[i] == FP_STRINGEX)
|
||||
{
|
||||
cell *tmp;
|
||||
amx_Allot((*iter)->pPlugin->getAMX(),
|
||||
amx_Allot(iter->pPlugin->getAMX(),
|
||||
(m_ParamTypes[i] == FP_STRING) ? strlen(reinterpret_cast<const char*>(params[i]))+1 : STRINGEX_MAXLENGTH,
|
||||
&realParams[i], &tmp);
|
||||
amx_SetString(tmp, (const char *)(params[i]), 0, 0);
|
||||
@ -88,7 +86,7 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
|
||||
else if (m_ParamTypes[i] == FP_ARRAY)
|
||||
{
|
||||
cell *tmp;
|
||||
amx_Allot((*iter)->pPlugin->getAMX(), preparedArrays[params[i]].size,
|
||||
amx_Allot(iter->pPlugin->getAMX(), preparedArrays[params[i]].size,
|
||||
&realParams[i], &tmp);
|
||||
physAddrs[i] = tmp;
|
||||
if (preparedArrays[params[i]].type == Type_Cell)
|
||||
@ -109,23 +107,23 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
|
||||
}
|
||||
// exec
|
||||
cell retVal;
|
||||
int err = amx_Execv((*iter)->pPlugin->getAMX(), &retVal, (*iter)->func, m_NumParams, realParams);
|
||||
int err = amx_Execv(iter->pPlugin->getAMX(), &retVal, iter->func, m_NumParams, realParams);
|
||||
// log runtime error, if any
|
||||
if (err != AMX_ERR_NONE)
|
||||
AMXXLOG_Log("[AMXX] Run time error %d on line %ld (plugin \"%s\")", err, (*iter)->pPlugin->getAMX()->curline, (*iter)->pPlugin->getName());
|
||||
AMXXLOG_Log("[AMXX] Run time error %d on line %ld (plugin \"%s\")", err, iter->pPlugin->getAMX()->curline, iter->pPlugin->getName());
|
||||
|
||||
// cleanup strings & arrays
|
||||
for (i = 0; i < m_NumParams; ++i)
|
||||
{
|
||||
if (m_ParamTypes[i] == FP_STRING)
|
||||
{
|
||||
amx_Release((*iter)->pPlugin->getAMX(), realParams[i]);
|
||||
amx_Release(iter->pPlugin->getAMX(), realParams[i]);
|
||||
}
|
||||
else if (m_ParamTypes[i] == FP_STRINGEX)
|
||||
{
|
||||
// copy back
|
||||
amx_GetString(reinterpret_cast<char*>(params[i]), physAddrs[i], 0);
|
||||
amx_Release((*iter)->pPlugin->getAMX(), realParams[i]);
|
||||
amx_Release(iter->pPlugin->getAMX(), realParams[i]);
|
||||
}
|
||||
else if (m_ParamTypes[i] == FP_ARRAY)
|
||||
{
|
||||
@ -141,7 +139,7 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
|
||||
for (unsigned int j = 0; j < preparedArrays[params[i]].size; ++j)
|
||||
*data++ = static_cast<char>(*tmp++ & 0xFF);
|
||||
}
|
||||
amx_Release((*iter)->pPlugin->getAMX(), realParams[i]);
|
||||
amx_Release(iter->pPlugin->getAMX(), realParams[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -351,7 +349,7 @@ void CForwardMngr::clear()
|
||||
{
|
||||
for (ForwardVec::iterator iter = m_Forwards.begin(); iter != m_Forwards.end(); ++iter)
|
||||
{
|
||||
delete (*iter);
|
||||
delete *iter;
|
||||
}
|
||||
SPForwardVec::iterator spIter;
|
||||
for (spIter = m_SPForwards.begin(); spIter != m_SPForwards.end(); ++spIter)
|
||||
|
@ -92,13 +92,13 @@ class CForward
|
||||
CPluginMngr::CPlugin *pPlugin;
|
||||
int func;
|
||||
};
|
||||
typedef CVector<AMXForward*> AMXForwardList;
|
||||
typedef CVector<AMXForward> AMXForwardList;
|
||||
AMXForwardList m_Funcs;
|
||||
ForwardParam m_ParamTypes[FORWARD_MAX_PARAMS];
|
||||
public:
|
||||
CForward(const char *name, ForwardExecType et, int numParams, const ForwardParam * paramTypes);
|
||||
CForward()
|
||||
{ } // leaves everything unitialized
|
||||
{ } // leaves everything unitialized'
|
||||
cell execute(cell *params, ForwardPreparedArray *preparedArrays);
|
||||
int getParamsNum() const
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user