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