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)
|
if ((*iter).isValid() && amx_FindPublic((*iter).getAMX(), name, &func) == AMX_ERR_NONE)
|
||||||
{
|
{
|
||||||
tmp = new AMXForward;
|
AMXForward tmp;
|
||||||
if (!tmp)
|
tmp.pPlugin = &(*iter);
|
||||||
return; // :TODO: Better error report!!!
|
tmp.func = func;
|
||||||
tmp->pPlugin = &(*iter);
|
|
||||||
tmp->func = func;
|
|
||||||
m_Funcs.push_back(tmp);
|
m_Funcs.push_back(tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,11 +64,11 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
|
||||||
|
|
||||||
unsigned int id = 0;
|
unsigned int id = 0;
|
||||||
|
|
||||||
CVector<AMXForward *>::iterator iter;
|
AMXForwardList::iterator iter;
|
||||||
|
|
||||||
for (iter = m_Funcs.begin(); iter != m_Funcs.end(); 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
|
// handle strings & arrays
|
||||||
int i;
|
int i;
|
||||||
|
@ -79,7 +77,7 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
|
||||||
if (m_ParamTypes[i] == FP_STRING || m_ParamTypes[i] == FP_STRINGEX)
|
if (m_ParamTypes[i] == FP_STRING || m_ParamTypes[i] == FP_STRINGEX)
|
||||||
{
|
{
|
||||||
cell *tmp;
|
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,
|
(m_ParamTypes[i] == FP_STRING) ? strlen(reinterpret_cast<const char*>(params[i]))+1 : STRINGEX_MAXLENGTH,
|
||||||
&realParams[i], &tmp);
|
&realParams[i], &tmp);
|
||||||
amx_SetString(tmp, (const char *)(params[i]), 0, 0);
|
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)
|
else if (m_ParamTypes[i] == FP_ARRAY)
|
||||||
{
|
{
|
||||||
cell *tmp;
|
cell *tmp;
|
||||||
amx_Allot((*iter)->pPlugin->getAMX(), preparedArrays[params[i]].size,
|
amx_Allot(iter->pPlugin->getAMX(), preparedArrays[params[i]].size,
|
||||||
&realParams[i], &tmp);
|
&realParams[i], &tmp);
|
||||||
physAddrs[i] = tmp;
|
physAddrs[i] = tmp;
|
||||||
if (preparedArrays[params[i]].type == Type_Cell)
|
if (preparedArrays[params[i]].type == Type_Cell)
|
||||||
|
@ -109,23 +107,23 @@ cell CForward::execute(cell *params, ForwardPreparedArray *preparedArrays)
|
||||||
}
|
}
|
||||||
// exec
|
// exec
|
||||||
cell retVal;
|
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
|
// log runtime error, if any
|
||||||
if (err != AMX_ERR_NONE)
|
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
|
// cleanup strings & arrays
|
||||||
for (i = 0; i < m_NumParams; ++i)
|
for (i = 0; i < m_NumParams; ++i)
|
||||||
{
|
{
|
||||||
if (m_ParamTypes[i] == FP_STRING)
|
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)
|
else if (m_ParamTypes[i] == FP_STRINGEX)
|
||||||
{
|
{
|
||||||
// copy back
|
// copy back
|
||||||
amx_GetString(reinterpret_cast<char*>(params[i]), physAddrs[i], 0);
|
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)
|
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)
|
for (unsigned int j = 0; j < preparedArrays[params[i]].size; ++j)
|
||||||
*data++ = static_cast<char>(*tmp++ & 0xFF);
|
*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)
|
for (ForwardVec::iterator iter = m_Forwards.begin(); iter != m_Forwards.end(); ++iter)
|
||||||
{
|
{
|
||||||
delete (*iter);
|
delete *iter;
|
||||||
}
|
}
|
||||||
SPForwardVec::iterator spIter;
|
SPForwardVec::iterator spIter;
|
||||||
for (spIter = m_SPForwards.begin(); spIter != m_SPForwards.end(); ++spIter)
|
for (spIter = m_SPForwards.begin(); spIter != m_SPForwards.end(); ++spIter)
|
||||||
|
|
|
@ -92,13 +92,13 @@ class CForward
|
||||||
CPluginMngr::CPlugin *pPlugin;
|
CPluginMngr::CPlugin *pPlugin;
|
||||||
int func;
|
int func;
|
||||||
};
|
};
|
||||||
typedef CVector<AMXForward*> AMXForwardList;
|
typedef CVector<AMXForward> AMXForwardList;
|
||||||
AMXForwardList m_Funcs;
|
AMXForwardList m_Funcs;
|
||||||
ForwardParam m_ParamTypes[FORWARD_MAX_PARAMS];
|
ForwardParam m_ParamTypes[FORWARD_MAX_PARAMS];
|
||||||
public:
|
public:
|
||||||
CForward(const char *name, ForwardExecType et, int numParams, const ForwardParam * paramTypes);
|
CForward(const char *name, ForwardExecType et, int numParams, const ForwardParam * paramTypes);
|
||||||
CForward()
|
CForward()
|
||||||
{ } // leaves everything unitialized
|
{ } // leaves everything unitialized'
|
||||||
cell execute(cell *params, ForwardPreparedArray *preparedArrays);
|
cell execute(cell *params, ForwardPreparedArray *preparedArrays);
|
||||||
int getParamsNum() const
|
int getParamsNum() const
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user