diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp index 127d6d34..c19cbf4b 100644 --- a/src/CBot/CBotClass.cpp +++ b/src/CBot/CBotClass.cpp @@ -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::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; diff --git a/src/CBot/CBotInstr/CBotDefClass.cpp b/src/CBot/CBotInstr/CBotDefClass.cpp index 3fe832e5..bd885e10 100644 --- a/src/CBot/CBotInstr/CBotDefClass.cpp +++ b/src/CBot/CBotInstr/CBotDefClass.cpp @@ -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); diff --git a/src/CBot/CBotInstr/CBotFunction.cpp b/src/CBot/CBotInstr/CBotFunction.cpp index 7852c7ef..ddbd3667 100644 --- a/src/CBot/CBotInstr/CBotFunction.cpp +++ b/src/CBot/CBotInstr/CBotFunction.cpp @@ -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()) diff --git a/src/CBot/CBotInstr/CBotInstrCall.cpp b/src/CBot/CBotInstr/CBotInstrCall.cpp index 6b45bb52..86e37f72 100644 --- a/src/CBot/CBotInstr/CBotInstrCall.cpp +++ b/src/CBot/CBotInstr/CBotInstrCall.cpp @@ -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; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/CBotInstr/CBotInstrMethode.cpp b/src/CBot/CBotInstr/CBotInstrMethode.cpp index 3a41802c..f4cda036 100644 --- a/src/CBot/CBotInstr/CBotInstrMethode.cpp +++ b/src/CBot/CBotInstr/CBotInstrMethode.cpp @@ -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; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/CBotInstr/CBotNew.cpp b/src/CBot/CBotInstr/CBotNew.cpp index ddd50c69..9fab3824 100644 --- a/src/CBot/CBotInstr/CBotNew.cpp +++ b/src/CBot/CBotInstr/CBotNew.cpp @@ -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; } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp index 6afcc754..70ec5631 100644 --- a/src/CBot/CBotStack.cpp +++ b/src/CBot/CBotStack.cpp @@ -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 { diff --git a/src/CBot/CBotTypResult.cpp b/src/CBot/CBotTypResult.cpp index 46d42eef..d7005c2a 100644 --- a/src/CBot/CBotTypResult.cpp +++ b/src/CBot/CBotTypResult.cpp @@ -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; } diff --git a/src/CBot/CBotVar/CBotVar.cpp b/src/CBot/CBotVar/CBotVar.cpp index 4e88cd69..7ea659f5 100644 --- a/src/CBot/CBotVar/CBotVar.cpp +++ b/src/CBot/CBotVar/CBotVar.cpp @@ -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; } ////////////////////////////////////////////////////////////////////////////////