Fix memory leaks in CBOT engine
parent
64bc1f1afb
commit
8e54f7ca9c
|
@ -83,7 +83,11 @@ CBotClass* CBotClass::Create(const std::string& name,
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
void CBotClass::ClearPublic()
|
||||
{
|
||||
m_publicClasses.clear();
|
||||
while ( !m_publicClasses.empty() )
|
||||
{
|
||||
auto it = m_publicClasses.begin();
|
||||
delete *it; // calling destructor removes the class from the list
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -593,17 +597,16 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
|
|||
else
|
||||
{
|
||||
// return a method precompiled in pass 1
|
||||
CBotToken* ppp = p;
|
||||
CBotCStack* pStk = pStack->TokenStack(nullptr, true);
|
||||
CBotDefParam* params = CBotDefParam::Compile(p, pStk );
|
||||
delete pStk;
|
||||
p = ppp;
|
||||
std::list<CBotFunction*>::iterator pfIter = std::find_if(m_pMethod.begin(), m_pMethod.end(), [&pp, ¶ms](CBotFunction* x)
|
||||
{
|
||||
return x->GetName() == pp && x->CheckParam( params );
|
||||
});
|
||||
assert(pfIter != m_pMethod.end());
|
||||
CBotFunction* pf = *pfIter;
|
||||
delete params;
|
||||
|
||||
bool bConstructor = (pp == GetName());
|
||||
CBotCStack* pile = pStack->TokenStack(nullptr, true);
|
||||
|
@ -690,7 +693,6 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
|
|||
if (i == nullptr || pStack->GetType() != CBotTypInt) // must be a number
|
||||
{
|
||||
pStack->SetError(CBotErrBadIndex, p->GetStart());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -701,8 +703,9 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
|
|||
if (limites == nullptr) limites = i;
|
||||
else limites->AddNext3(i);
|
||||
|
||||
if (IsOfType(p, ID_CLBRK)) continue;
|
||||
if (pStack->IsOk() && IsOfType(p, ID_CLBRK)) continue;
|
||||
pStack->SetError(CBotErrCloseIndex, p->GetStart());
|
||||
delete limites;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -775,7 +778,10 @@ bool CBotClass::CompileDefItem(CBotToken* &p, CBotCStack* pStack, bool bSecond)
|
|||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
delete i;
|
||||
delete limites;
|
||||
}
|
||||
|
||||
if ( IsOfType(p, ID_COMMA) ) continue;
|
||||
if ( IsOfType(p, ID_SEP) ) break;
|
||||
|
|
|
@ -51,6 +51,9 @@ CBotDefClass::CBotDefClass()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotDefClass::~CBotDefClass()
|
||||
{
|
||||
delete m_parameters;
|
||||
delete m_exprRetVar;
|
||||
delete m_expr;
|
||||
delete m_var;
|
||||
}
|
||||
|
||||
|
@ -246,9 +249,9 @@ bool CBotDefClass::Execute(CBotStack* &pj)
|
|||
|
||||
if (m_exprRetVar != nullptr) // Class c().method();
|
||||
{
|
||||
if (pile->IfStep()) return false;
|
||||
if (pile->GetState() == 4)
|
||||
{
|
||||
if (pile->IfStep()) return false;
|
||||
CBotStack* pile3 = pile->AddStack();
|
||||
if (!m_exprRetVar->Execute(pile3)) return false;
|
||||
pile3->SetVar(nullptr);
|
||||
|
|
|
@ -185,6 +185,7 @@ CBotFunction* CBotFunction::Compile(CBotToken* &p, CBotCStack* pStack, CBotFunct
|
|||
|
||||
}
|
||||
func->m_openpar = *p;
|
||||
delete func->m_param;
|
||||
func->m_param = CBotDefParam::Compile(p, pStk );
|
||||
func->m_closepar = *(p->GetPrev());
|
||||
if (pStk->IsOk())
|
||||
|
|
|
@ -36,6 +36,7 @@ namespace CBot
|
|||
CBotInstrCall::CBotInstrCall()
|
||||
{
|
||||
m_parameters = nullptr;
|
||||
m_exprRetVar = nullptr;
|
||||
m_nFuncIdent = 0;
|
||||
}
|
||||
|
||||
|
@ -43,6 +44,7 @@ CBotInstrCall::CBotInstrCall()
|
|||
CBotInstrCall::~CBotInstrCall()
|
||||
{
|
||||
delete m_parameters;
|
||||
delete m_exprRetVar;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -36,6 +36,7 @@ namespace CBot
|
|||
CBotInstrMethode::CBotInstrMethode()
|
||||
{
|
||||
m_parameters = nullptr;
|
||||
m_exprRetVar = nullptr;
|
||||
m_MethodeIdent = 0;
|
||||
}
|
||||
|
||||
|
@ -43,6 +44,7 @@ CBotInstrMethode::CBotInstrMethode()
|
|||
CBotInstrMethode::~CBotInstrMethode()
|
||||
{
|
||||
delete m_parameters;
|
||||
delete m_exprRetVar;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -36,12 +36,15 @@ namespace CBot
|
|||
CBotNew::CBotNew()
|
||||
{
|
||||
m_parameters = nullptr;
|
||||
m_exprRetVar = nullptr;
|
||||
m_nMethodeIdent = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CBotNew::~CBotNew()
|
||||
{
|
||||
delete m_parameters;
|
||||
delete m_exprRetVar;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -737,11 +737,11 @@ bool CBotStack::RestoreState(FILE* pf, CBotStack* &pStack)
|
|||
{
|
||||
unsigned short w;
|
||||
|
||||
pStack = nullptr;
|
||||
if (pStack != this) pStack = nullptr;
|
||||
if (!ReadWord(pf, w)) return false;
|
||||
if ( w == 0 ) return true; // 0 - terminator
|
||||
|
||||
pStack = AddStack();
|
||||
if (pStack == nullptr) pStack = AddStack();
|
||||
|
||||
if ( w == 2 ) // 2 - m_next2
|
||||
{
|
||||
|
|
|
@ -167,11 +167,16 @@ CBotTypResult& CBotTypResult::operator=(const CBotTypResult& src)
|
|||
m_type = src.m_type;
|
||||
m_limite = src.m_limite;
|
||||
m_class = src.m_class;
|
||||
m_next = nullptr;
|
||||
if (src.m_next != nullptr )
|
||||
{
|
||||
delete m_next;
|
||||
m_next = new CBotTypResult(*src.m_next);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete m_next;
|
||||
m_next = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "CBot/CBotStack.h"
|
||||
|
||||
#include "CBot/CBotInstr/CBotInstr.h"
|
||||
#include "CBot/CBotVar/CBotVarArray.h"
|
||||
#include "CBot/CBotVar/CBotVarPointer.h"
|
||||
#include "CBot/CBotVar/CBotVarClass.h"
|
||||
|
@ -70,6 +71,8 @@ CBotVar::CBotVar(const CBotToken &name) : CBotVar()
|
|||
CBotVar::~CBotVar( )
|
||||
{
|
||||
delete m_token;
|
||||
delete m_InitExpr;
|
||||
delete m_LimExpr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue