delete of opt arguments corrected. 18/14818/6
Cedric Delamarre [Mon, 7 Jul 2014 15:21:05 +0000 (17:21 +0200)]
Change-Id: Ie7a938fcdf5cbdd70b999a62ef3d72cbecc52f9e

scilab/modules/ast/includes/ast/runvisitor.hxx
scilab/modules/ast/includes/types/arrayof.hxx
scilab/modules/ast/src/cpp/ast/run_AssignExp.cpp
scilab/modules/ast/src/cpp/ast/run_CallExp.cpp
scilab/modules/ast/src/cpp/ast/runvisitor.cpp
scilab/modules/ast/src/cpp/ast/visitor_common.cpp
scilab/modules/ast/src/cpp/system_env/configvariable.cpp
scilab/modules/ast/src/cpp/types/list.cpp
scilab/modules/types/sci_gateway/cpp/sci_tlist_or_mlist.hxx

index 9d25631..a41ce83 100644 (file)
@@ -308,6 +308,8 @@ public:
             {
                 if (o->second)
                 {
+                    //decreasef ref after increaseref in callexp
+                    o->second->DecreaseRef();
                     o->second->killMe();
                 }
             }
index b8f19d6..bd66340 100644 (file)
@@ -590,9 +590,9 @@ public :
         //free pArg content
         for (int iArg = 0 ; iArg < pArg.size() ; iArg++)
         {
-            if (pArg[iArg] != (*_pArgs)[iArg] && pArg[iArg]->isDeletable())
+            if (pArg[iArg] != (*_pArgs)[iArg])
             {
-                delete pArg[iArg];
+                pArg[iArg]->killMe();
             }
         }
 
@@ -663,10 +663,7 @@ public :
             if (piMaxDim[i] == 1)
             {
                 iDims--;
-                if (pArg.back()->isDeletable())
-                {
-                    delete pArg.back();
-                }
+                pArg.back()->killMe();
                 pArg.pop_back();
             }
             else
@@ -723,9 +720,9 @@ public :
         //free pArg content
         for (int iArg = 0 ; iArg < pArg.size() ; iArg++)
         {
-            if (pArg[iArg] != (*_pArgs)[iArg] && pArg[iArg]->isDeletable())
+            if (pArg[iArg] != (*_pArgs)[iArg])
             {
-                delete pArg[iArg];
+                pArg[iArg]->killMe();
             }
         }
 
@@ -975,9 +972,9 @@ public :
         //free pArg content
         for (int iArg = 0 ; iArg < pArg.size() ; iArg++)
         {
-            if (pArg[iArg] != (*_pArgs)[iArg] && pArg[iArg]->isDeletable())
+            if (pArg[iArg] != (*_pArgs)[iArg])
             {
-                delete pArg[iArg];
+                pArg[iArg]->killMe();
             }
         }
 
@@ -1211,9 +1208,9 @@ public :
         //free pArg content
         for (int iArg = 0 ; iArg < pArg.size() ; iArg++)
         {
-            if (pArg[iArg] != (*_pArgs)[iArg] && pArg[iArg]->isDeletable())
+            if (pArg[iArg] != (*_pArgs)[iArg])
             {
-                delete pArg[iArg];
+                pArg[iArg]->killMe();
             }
         }
 
index b622433..82294e9 100644 (file)
@@ -233,10 +233,7 @@ void RunVisitorT<T>::visitprivate(const AssignExp  &e)
                 VariableToString(pOut, wcsVarName);
             }
 
-            if (pITR->isDeletable())
-            {
-                delete pITR;
-            }
+            pITR->killMe();
 
             result_clear();
             return;
index af49b5b..404dfac 100644 (file)
@@ -62,6 +62,9 @@ void RunVisitorT<T>::visitprivate(const CallExp &e)
                 Exp* pR = &pAssign->right_exp_get();
                 pR->accept(*this);
                 InternalType* pITR = result_get();
+                // IncreaseRef to protect opt argument of scope_end delete
+                // It will be deleted by clear_opt
+                pITR->IncreaseRef();
 
                 if (pIT->hasInvokeOption())
                 {
@@ -75,7 +78,6 @@ void RunVisitorT<T>::visitprivate(const CallExp &e)
                 }
                 else
                 {
-                    pITR->IncreaseRef();
                     in.push_back(pITR);
                 }
 
@@ -235,10 +237,7 @@ void RunVisitorT<T>::visitprivate(const CellCallExp &e)
             //clean pArgs return by GetArgumentList
             for (int iArg = 0 ; iArg < (int)pArgs->size() ; iArg++)
             {
-                if ((*pArgs)[iArg]->isDeletable())
-                {
-                    delete (*pArgs)[iArg];
-                }
+                (*pArgs)[iArg]->killMe();
             }
             delete pArgs;
         }
index afa0572..38fe3f3 100644 (file)
@@ -322,10 +322,7 @@ void RunVisitorT<T>::visitprivate(const WhileExp  &e)
         //clear old result value before evaluate new one
         if (result_get() != NULL)
         {
-            if (result_get()->isDeletable())
-            {
-                delete result_get();
-            }
+            result_get()->killMe();
         }
 
         e.test_get().accept(*this);
index 426f729..1faf270 100644 (file)
@@ -1544,9 +1544,9 @@ InternalType* insertionCall(const ast::Exp& e, typed_list* _pArgs, InternalType*
 
             if (_pArgs->size() != 1 || pS->isScalar() == false)
             {
-                if (pIL && pIL->isDeletable())
+                if (pIL)
                 {
-                    delete pIL;
+                    pIL->killMe();
                 }
                 //manage error
                 std::wostringstream os;
@@ -1775,9 +1775,9 @@ InternalType* insertionCall(const ast::Exp& e, typed_list* _pArgs, InternalType*
                 String *pS = (*_pArgs)[0]->getAs<types::String>();
                 if (pS->isScalar() == false)
                 {
-                    if (pIL && pIL->isDeletable())
+                    if (pIL)
                     {
-                        delete pIL;
+                        pIL->killMe();
                     }
                     //manage error
                     std::wostringstream os;
@@ -1861,9 +1861,9 @@ InternalType* insertionCall(const ast::Exp& e, typed_list* _pArgs, InternalType*
                     String *pS = (*_pArgs)[0]->getAs<types::String>();
                     if (pS->isScalar() == false)
                     {
-                        if (pIL && pIL->isDeletable())
+                        if (pIL)
                         {
-                            delete pIL;
+                            pIL->killMe();
                         }
 
                         //manage error
@@ -1983,9 +1983,9 @@ InternalType* insertionCall(const ast::Exp& e, typed_list* _pArgs, InternalType*
         pOut = pRet;
     }
 
-    if (pIL && pIL->isDeletable())
+    if (pIL)
     {
-        delete pIL;
+        pIL->killMe();
     }
 
     return pOut;
index dcc82d6..8ebc53f 100644 (file)
@@ -555,7 +555,7 @@ void ConfigVariable::deleteThread(__threadKey _key)
             (*it)->DecreaseRef();
             if ((*it)->isDeletable())
             {
-                delete (*it);
+                (*it)->killMe();
                 (*it) = NULL;
                 m_threadList.erase(it);
                 return;
index 060a875..4964db4 100644 (file)
@@ -49,10 +49,7 @@ List::~List()
         for (itValues = m_plData->begin() ; itValues != m_plData->end() ; ++itValues)
         {
             (*itValues)->DecreaseRef();
-            if ((*itValues)->isDeletable())
-            {
-                delete *itValues;
-            }
+            (*itValues)->killMe();
         }
         delete m_plData;
     }
@@ -186,9 +183,9 @@ std::vector<InternalType*>  List::extract(typed_list* _pArgs)
     //free pArg content
     for (int iArg = 0 ; iArg < pArg.size() ; iArg++)
     {
-        if (pArg[iArg] != (*_pArgs)[iArg] && pArg[iArg]->isDeletable())
+        if (pArg[iArg] != (*_pArgs)[iArg])
         {
-            delete pArg[iArg];
+            pArg[iArg]->killMe();
         }
     }
 
@@ -238,9 +235,9 @@ InternalType* List::insert(typed_list* _pArgs, InternalType* _pSource)
         else if (idx <= m_plData->size())
         {
             InternalType* pIT = (*m_plData)[idx - 1];
-            if (pIT && pIT->isDeletable())
+            if (pIT)
             {
-                delete pIT;
+                pIT->killMe();
             }
             m_plData->erase(m_plData->begin() + idx - 1);
         }
@@ -292,9 +289,9 @@ InternalType* List::insert(typed_list* _pArgs, InternalType* _pSource)
 
         InternalType* pIT = (*m_plData)[idx - 1];
         pIT->DecreaseRef();
-        if (pIT && pIT->isDeletable())
+        if (pIT)
         {
-            delete pIT;
+            pIT->killMe();
         }
 
         (*m_plData)[idx - 1] = _pSource->clone();
@@ -306,9 +303,9 @@ InternalType* List::insert(typed_list* _pArgs, InternalType* _pSource)
     //free pArg content
     for (int iArg = 0 ; iArg < pArg.size() ; iArg++)
     {
-        if (pArg[iArg] != (*_pArgs)[iArg] && pArg[iArg]->isDeletable())
+        if (pArg[iArg] != (*_pArgs)[iArg])
         {
-            delete pArg[iArg];
+            pArg[iArg]->killMe();
         }
     }
 
@@ -347,10 +344,7 @@ bool List::set(const int _iIndex, InternalType* _pIT)
     if (pOld)
     {
         pOld->DecreaseRef();
-        if (pOld->isDeletable())
-        {
-            delete pOld;
-        }
+        pOld->killMe();
     }
 
     return true;
index 397ebe4..0317dd4 100644 (file)
@@ -49,7 +49,7 @@ Function::ReturnValue sci_tlist_or_mlist(typed_list &in, int _piRetCount, typed_
     String* pS = in[0]->getAs<types::String>();
 
     //check for rational type
-    if(pS->getSize() > 0 && wcscmp(pS->get(0), L"r") == 0)
+    if (pS->getSize() > 0 && wcscmp(pS->get(0), L"r") == 0)
     {
         Scierror(999, _("%ls: Can not create a %ls with input argument #%d.\n"), _pstrFunName, _pstrFunName, 1);
         return Function::Error;
@@ -85,7 +85,7 @@ Function::ReturnValue sci_tlist_or_mlist(typed_list &in, int _piRetCount, typed_
     {
         pRetVal->append(pITEmpty);
     }
-    delete pITEmpty;
+    pITEmpty->killMe();
 
     out.push_back(pRetVal);
     return Function::OK;