fix ast tests memory leaks 66/16166/7
Antoine ELIAS [Tue, 17 Mar 2015 17:16:20 +0000 (18:16 +0100)]
Change-Id: Id98f118b1f0c289334e11994eef4e6c4dfda3a30

32 files changed:
scilab/modules/api_scilab/src/cpp/api_list.cpp
scilab/modules/api_scilab/src/cpp/api_poly.cpp
scilab/modules/ast/includes/symbol/variables.hxx
scilab/modules/ast/includes/system_env/configvariable.hxx
scilab/modules/ast/includes/types/polynom.hxx
scilab/modules/ast/includes/types/sparseOp.hxx
scilab/modules/ast/src/cpp/ast/run_AssignExp.hpp
scilab/modules/ast/src/cpp/ast/run_MatrixExp.hpp
scilab/modules/ast/src/cpp/ast/runvisitor.cpp
scilab/modules/ast/src/cpp/ast/visitor_common.cpp
scilab/modules/ast/src/cpp/operations/types_addition.cpp
scilab/modules/ast/src/cpp/operations/types_divide.cpp
scilab/modules/ast/src/cpp/operations/types_dotdivide.cpp
scilab/modules/ast/src/cpp/operations/types_subtraction.cpp
scilab/modules/ast/src/cpp/symbol/context.cpp
scilab/modules/ast/src/cpp/system_env/configvariable.cpp
scilab/modules/ast/src/cpp/types/arrayof.cpp
scilab/modules/ast/src/cpp/types/cell.cpp
scilab/modules/ast/src/cpp/types/double.cpp
scilab/modules/ast/src/cpp/types/list.cpp
scilab/modules/ast/src/cpp/types/polynom.cpp
scilab/modules/ast/src/cpp/types/sparse.cpp
scilab/modules/ast/src/cpp/types/string.cpp
scilab/modules/ast/src/cpp/types/struct.cpp
scilab/modules/ast/src/cpp/types/types_tools.cpp
scilab/modules/ast/tests/unit_tests/matrix_exp.dia.ref
scilab/modules/ast/tests/unit_tests/matrix_exp.tst
scilab/modules/core/src/cpp/InitScilab.cpp
scilab/modules/dynamic_link/sci_gateway/cpp/sci_link.cpp
scilab/modules/dynamic_link/sci_gateway/cpp/sci_ulink.cpp
scilab/modules/polynomials/sci_gateway/cpp/sci_simp.cpp
scilab/modules/sparse/sci_gateway/cpp/sci_sparse.cpp

index 3ef4b36..99e2f0e 100644 (file)
@@ -1259,7 +1259,8 @@ SciErr createCommonMatrixOfPolyInList(void* _pvCtx, const char* _pstName, int* _
     }
 
     wchar_t* pstTemp = to_wide_string(_pstVarName);
-    Polynom* pP = new Polynom(pstTemp, _iRows, _iCols, _piNbCoef);
+    std::wstring wstTemp(pstTemp);
+    Polynom* pP = new Polynom(wstTemp, _iRows, _iCols, _piNbCoef);
     FREE(pstTemp);
     if (pP == NULL)
     {
index 4a68ff6..4ff0b50 100644 (file)
@@ -196,7 +196,8 @@ SciErr createCommonMatrixOfPoly(void* _pvCtx, int _iVar, int _iComplex, char* _p
     }
 
     wchar_t* pstTemp = to_wide_string(_pstVarName);
-    Polynom* pP = new Polynom(pstTemp, _iRows, _iCols, _piNbCoef);
+    std::wstring wstTemp(pstTemp);
+    Polynom* pP = new Polynom(wstTemp, _iRows, _iCols, _piNbCoef);
     FREE(pstTemp);
     if (pP == NULL)
     {
@@ -259,7 +260,8 @@ SciErr createCommonNamedMatrixOfPoly(void* _pvCtx, const char* _pstName, char* _
     }
 
     wchar_t* pstTemp = to_wide_string(_pstVarName);
-    Polynom* pP = new Polynom(pstTemp, _iRows, _iCols, _piNbCoef);
+    std::wstring wstTemp(pstTemp);
+    Polynom* pP = new Polynom(wstTemp, _iRows, _iCols, _piNbCoef);
     FREE(pstTemp);
     if (pP == NULL)
     {
index 7119d74..9df077b 100644 (file)
@@ -428,6 +428,8 @@ struct Variables
             ScopedVariable* pVar = _var->top();
             _var->pop();
             putInPreviousScope(_var, _pIT, _iLevel);
+            //decresef ref before, increase it in put
+            pVar->m_pIT->DecreaseRef();
             _var->put(pVar->m_pIT, pVar->m_iLevel);
             delete pVar;
         }
index 958c9d3..8838c5c 100644 (file)
@@ -49,24 +49,24 @@ private :
     static std::wstring m_SCIPath;
 
 public :
-    static void setSCIPath(std::wstring& _SCIPath);
-    static std::wstring getSCIPath();
+    static void setSCIPath(const std::wstring& _SCIPath);
+    static std::wstring& getSCIPath();
 
     //SCIHOME
 private :
     static std::wstring m_SCIHOME;
 
 public :
-    static void setSCIHOME(std::wstring& _m_SCIHOME);
-    static std::wstring getSCIHOME();
+    static void setSCIHOME(const std::wstring& _m_SCIHOME);
+    static std::wstring& getSCIHOME();
 
     //TMPDIR
 private :
     static std::wstring m_TMPDIR;
 
 public :
-    static void setTMPDIR(std::wstring& _TMPDIR);
-    static std::wstring getTMPDIR();
+    static void setTMPDIR(const std::wstring& _TMPDIR);
+    static std::wstring& getTMPDIR();
 
     // Force Quit
 private :
@@ -138,8 +138,8 @@ private :
     static std::wstring m_HOME;
 
 public :
-    static void setHOME(std::wstring& _m_HOME);
-    static std::wstring getHOME();
+    static void setHOME(const std::wstring& _m_HOME);
+    static std::wstring& getHOME();
 
     //Clear last error information
 public :
@@ -157,8 +157,8 @@ private :
     static std::wstring m_wstError;
 
 public :
-    static void setLastErrorMessage(std::wstring _wstError);
-    static std::wstring getLastErrorMessage();
+    static void setLastErrorMessage(const std::wstring& _wstError);
+    static std::wstring& getLastErrorMessage();
 
     //Last Error ID
 private :
@@ -185,8 +185,8 @@ private :
     static std::wstring m_wstErrorFunction;
 
 public :
-    static void setLastErrorFunction(std::wstring _wstFunction);
-    static std::wstring getLastErrorFunction();
+    static void setLastErrorFunction(const std::wstring& _wstFunction);
+    static std::wstring& getLastErrorFunction();
 
     //Prompt Mode and Silent error
 public :
@@ -252,15 +252,15 @@ public :
 
     typedef struct
     {
-        wchar_t* pwstLibraryName;   /** name of dynamic library **/
-        DynLibHandle hLib;        /** handle of the library **/
+        std::wstring wstLibraryName;    /** name of dynamic library **/
+        DynLibHandle hLib;              /** handle of the library **/
     } DynamicLibraryStr;
 
     typedef void(*dynlib_ptr)();
 
     typedef struct
     {
-        wchar_t* pwstEntryPointName;    /** name of interface **/
+        std::wstring wstEntryPointName; /** name of interface **/
         int iLibIndex;                  /** name of interface **/
         dynlib_ptr functionPtr;         /** entrypoint for the interface **/
         bool bOK;                       /** flag set to TRUE if entrypoint can be used **/
@@ -272,8 +272,8 @@ private :
 public :
 
     /* tools fucntions */
-    static void setLibraryName(DynamicLibraryStr* _pDynamicLibrary, wchar_t* _pwstLibraryName);
-    static void setEntryPointName(EntryPointStr* _pEntryPoint, wchar_t* _pwstEntryPointName);
+    static void setLibraryName(DynamicLibraryStr* _pDynamicLibrary, const std::wstring& _wstLibraryName);
+    static void setEntryPointName(EntryPointStr* _pEntryPoint, const std::wstring& _wstEntryPointName);
 
     /* "Constructors" */
     static DynamicLibraryStr* getNewDynamicLibraryStr();
@@ -290,10 +290,9 @@ public :
     static std::list<EntryPointStr*>* getEntryPointList();
     static void addEntryPoint(EntryPointStr* _pEP);
     static void removeEntryPoint(int _iEntryPointIndex);
-    static EntryPointStr* getEntryPoint(wchar_t* _pwstEntryPointName, int _iDynamicLibraryIndex = -1);
-    static int getEntryPointPosition(wchar_t* _pwstEntryPointName, int _iDynamicLibraryIndex = -1);
+    static EntryPointStr* getEntryPoint(const std::wstring& _wstEntryPointName, int _iDynamicLibraryIndex = -1);
+    static int getEntryPointPosition(const std::wstring& _wstEntryPointName, int _iDynamicLibraryIndex = -1);
     static dynlib_ptr getEntryPointFromPosition(int position);
-
     static std::vector<std::wstring> getEntryPointNameList();
 
     //dynamic modules
@@ -399,9 +398,9 @@ private :
 private :
     static std::list<std::wstring> m_ReferenceModules;
 public :
-    static bool checkReferenceModule(std::wstring _module);
-    static void addReferenceModule(std::wstring _module);
-    static void removeReferenceModule(std::wstring _module);
+    static bool checkReferenceModule(const std::wstring& _module);
+    static void addReferenceModule(const std::wstring& _module);
+    static void removeReferenceModule(const std::wstring& _module);
     static std::list<std::wstring> getReferenceModules();
 
     //analyzer options
index 31a09af..c0c4f28 100644 (file)
@@ -37,10 +37,10 @@ class EXTERN_AST Polynom : public ArrayOf<SinglePoly*>
 {
 public :
     Polynom();
-    Polynom(std::wstring _szVarName, int _iRows, int _iCols);
-    Polynom(std::wstring _szVarName, int _iRows, int _iCols, const int *_piRank);
-    Polynom(std::wstring _szVarName, int _iDims, int* _piDims);
-    Polynom(std::wstring _szVarName, int _iDims, int* _piDims, const int *_piRank);
+    Polynom(std::wstring& _szVarName, int _iRows, int _iCols);
+    Polynom(std::wstring& _szVarName, int _iRows, int _iCols, const int *_piRank);
+    Polynom(std::wstring& _szVarName, int _iDims, int* _piDims);
+    Polynom(std::wstring& _szVarName, int _iDims, int* _piDims, const int *_piRank);
 
     virtual                 ~Polynom();
 
@@ -73,7 +73,7 @@ public :
     }
 
     void                    whoAmI(void);
-    std::wstring            getVariableName();
+    std::wstring&           getVariableName();
     void                    setVariableName(std::wstring);
     bool                    getSizes(int *_piSizes);
     bool                    getRank(int *_piRank);
@@ -120,7 +120,7 @@ public :
 
 protected :
     std::wstring            m_szVarName;
-    void                    createPoly(std::wstring _szVarName, int _iDims, int* _piDims, const int *_piRank);
+    void                    createPoly(std::wstring& _szVarName, int _iDims, int* _piDims, const int *_piRank);
 
 private :
     virtual bool            subMatrixToString(std::wostringstream& ostr, int* _piDims, int _iDims);
index 53373d9..0e4bc76 100644 (file)
@@ -301,9 +301,9 @@ types::SparseBool* cwiseOp(types::Sparse const& op1, types::Sparse const& op2)
 
         if (op2.isComplex())
         {
-            types::Sparse* temp = new types::Sparse(op1);
-            temp->toComplex();
-            res = cwiseOp(*temp->matrixCplx, *op2.matrixCplx, Op<std::complex<double> >());
+            types::Sparse temp(op1);
+            temp.toComplex();
+            res = cwiseOp(*temp.matrixCplx, *op2.matrixCplx, Op<std::complex<double> >());
         }
         else
         {
index 0848c92..3d05127 100644 (file)
@@ -330,6 +330,7 @@ void RunVisitorT<T>::visitprivate(const AssignExp  &e)
             {
                 //unprotect rhs
                 pIT[i]->DecreaseRef();
+                pIT[i]->killMe();
             }
 
             delete[] pIT;
@@ -375,20 +376,32 @@ void RunVisitorT<T>::visitprivate(const AssignExp  &e)
                 throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
             }
 
-            if (evaluateFields(pField, fields, pIT) == NULL)
+            try
             {
-                for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
+                if (evaluateFields(pField, fields, pIT) == NULL)
                 {
-                    delete *i;
+                    for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
+                    {
+                        delete *i;
+                    }
+                    std::wostringstream os;
+                    os << _W("Fields evaluation failed.");
+                    throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
                 }
-                std::wostringstream os;
-                os << _W("Fields evaluation failed.");
-                throw ast::ScilabError(os.str(), 999, e.getRightExp().getLocation());
             }
+            catch (ScilabError error)
+            {
+                for (auto i : fields)
+                {
+                    delete i;
+                }
 
-            for (std::list<ExpHistory*>::const_iterator i = fields.begin(), end = fields.end(); i != end; i++)
+                throw error;
+            }
+
+            for (auto i : fields)
             {
-                delete *i;
+                delete i;
             }
 
             if (e.isVerbose() && ConfigVariable::isPromptShow())
index 39613ef..d32b4c4 100644 (file)
@@ -40,8 +40,9 @@ void RunVisitorT<T>::visitprivate(const MatrixExp &e)
             if (cols.size() == 1)
             {
                 setResult(NULL); // Reset value on loop re-start
+
                 cols[0]->accept(*this);
-                //managet evstr('//xxx') for example
+                //manage evstr('//xxx') for example
                 if (getResult() == NULL)
                 {
                     setResult(Double::Empty());
@@ -58,7 +59,24 @@ void RunVisitorT<T>::visitprivate(const MatrixExp &e)
             for (col = cols.begin() ; col != cols.end() ; col++)
             {
                 setResult(NULL); // Reset value on loop re-start
-                (*col)->accept(*this);
+
+                try
+                {
+                    (*col)->accept(*this);
+                }
+                catch (ScilabError& error)
+                {
+                    if (poRow)
+                    {
+                        poRow->killMe();
+                    }
+                    if (poResult)
+                    {
+                        poResult->killMe();
+                    }
+
+                    throw error;
+                }
 
                 InternalType *pIT = getResult();
                 if (pIT == NULL)
@@ -66,7 +84,7 @@ void RunVisitorT<T>::visitprivate(const MatrixExp &e)
                     continue;
                 }
 
-                //reset result but whitout delete the value
+                //reset result but without delete the value
                 clearResultButFirst();
 
                 if (pIT->isImplicitList())
@@ -87,7 +105,18 @@ void RunVisitorT<T>::visitprivate(const MatrixExp &e)
                         }
                         else
                         {
-                            poRow = callOverloadMatrixExp(L"c", poRow, pIT);
+                            try
+                            {
+                                poRow = callOverloadMatrixExp(L"c", poRow, pIT);
+                            }
+                            catch (ScilabError& error)
+                            {
+                                if (poResult)
+                                {
+                                    poResult->killMe();
+                                }
+                                throw error;
+                            }
                         }
 
                         continue;
@@ -121,7 +150,19 @@ void RunVisitorT<T>::visitprivate(const MatrixExp &e)
                         poRow->isImplicitList() ||
                         pGT->getDims() > 2)
                 {
-                    poRow = callOverloadMatrixExp(L"c", poRow, pGT);
+                    try
+                    {
+                        poRow = callOverloadMatrixExp(L"c", poRow, pGT);
+                    }
+                    catch (ScilabError& error)
+                    {
+                        if (poResult)
+                        {
+                            poResult->killMe();
+                        }
+                        throw error;
+                    }
+
                     continue;
                 }
 
@@ -145,10 +186,14 @@ void RunVisitorT<T>::visitprivate(const MatrixExp &e)
                 if (pGT->isSparse() && pGTResult->isDouble())
                 {
                     poRow = new types::Sparse(*pGTResult->getAs<types::Double>());
+                    pGTResult->killMe();
+                    pGTResult = poRow->getAs<types::GenericType>();
                 }
                 else if (pGT->isSparseBool() && pGTResult->isBool()) // [Bool SparseBool] => [SparseBool SparseBool]
                 {
                     poRow = new types::SparseBool(*pGTResult->getAs<types::Bool>());
+                    pGTResult->killMe();
+                    pGTResult = poRow->getAs<types::GenericType>();
                 }
                 else if (pGT->isDollar() && pGTResult->isDouble())
                 {
@@ -192,7 +237,18 @@ void RunVisitorT<T>::visitprivate(const MatrixExp &e)
                 // call overload
                 if (p == NULL)
                 {
-                    poRow = callOverloadMatrixExp(L"c", pGTResult, pGT);
+                    try
+                    {
+                        poRow = callOverloadMatrixExp(L"c", pGTResult, pGT);
+                    }
+                    catch (ScilabError& error)
+                    {
+                        if (poResult)
+                        {
+                            poResult->killMe();
+                        }
+                        throw error;
+                    }
                     continue;
                 }
 
@@ -222,7 +278,14 @@ void RunVisitorT<T>::visitprivate(const MatrixExp &e)
             // management of concatenation with 1:$
             if (poRow->isImplicitList() || poResult->isImplicitList())
             {
-                poResult = callOverloadMatrixExp(L"f", poResult, poRow);
+                try
+                {
+                    poResult = callOverloadMatrixExp(L"f", poResult, poRow);
+                }
+                catch (ScilabError& error)
+                {
+                    throw error;
+                }
                 continue;
             }
 
@@ -234,14 +297,29 @@ void RunVisitorT<T>::visitprivate(const MatrixExp &e)
             if (pGT->isList() || pGTResult->isList() ||
                     pGT->isStruct() || pGTResult->isStruct())
             {
-                poResult = callOverloadMatrixExp(L"f", pGTResult, pGT);
+                try
+                {
+                    poResult = callOverloadMatrixExp(L"f", pGTResult, pGT);
+                }
+                catch (ScilabError& error)
+                {
+                    throw error;
+                }
+
                 continue;
             }
 
             // hypermatrix case, will call %hm_f_hm
             if (pGT->getDims() > 2)
             {
-                poResult = callOverloadMatrixExp(L"f", pGTResult, pGT);
+                try
+                {
+                    poResult = callOverloadMatrixExp(L"f", pGTResult, pGT);
+                }
+                catch (ScilabError& error)
+                {
+                    throw error;
+                }
                 continue;
             }
 
@@ -263,20 +341,35 @@ void RunVisitorT<T>::visitprivate(const MatrixExp &e)
             if (pGT->isSparse() && pGTResult->isDouble())
             {
                 poResult = new types::Sparse(*pGTResult->getAs<types::Double>());
+                pGTResult->killMe();
+                pGTResult = poResult->getAs<GenericType>();
             }
             else if (pGT->isSparseBool() && pGTResult->isBool()) // [Bool SparseBool] => [SparseBool SparseBool]
             {
                 poResult = new types::SparseBool(*pGTResult->getAs<types::Bool>());
+                pGTResult->killMe();
+                pGTResult = poResult->getAs<GenericType>();
             }
 
             InternalType* pNewSize = AddElementToVariable(NULL, poResult, pGTResult->getRows() + pGT->getRows(), pGT->getCols());
             InternalType* p = AddElementToVariable(pNewSize, pGT, pGTResult->getRows(), 0);
+            if (p != pNewSize)
+            {
+                pNewSize->killMe();
+            }
 
             // call overload
             if (p == NULL)
             {
                 pNewSize->killMe();
-                poResult = callOverloadMatrixExp(L"f", pGTResult, pGT);
+                try
+                {
+                    poResult = callOverloadMatrixExp(L"f", pGTResult, pGT);
+                }
+                catch (ScilabError& error)
+                {
+                    throw error;
+                }
                 continue;
             }
 
@@ -321,13 +414,26 @@ types::InternalType* RunVisitorT<T>::callOverloadMatrixExp(std::wstring strType,
     in.push_back(_paramL);
     in.push_back(_paramR);
 
-    if (_paramR->isGenericType() && _paramR->getAs<types::GenericType>()->getDims() > 2)
+    try
+    {
+        if (_paramR->isGenericType() && _paramR->getAs<types::GenericType>()->getDims() > 2)
+        {
+            Ret = Overload::call(L"%hm_" + strType + L"_hm", in, 1, out, this, true);
+        }
+        else
+        {
+            Ret = Overload::call(L"%" + _paramL->getAs<List>()->getShortTypeStr() + L"_" + strType + L"_" + _paramR->getAs<List>()->getShortTypeStr(), in, 1, out, this, true);
+        }
+    }
+    catch (ast::ScilabError error)
     {
-        Ret = Overload::call(L"%hm_" + strType + L"_hm", in, 1, out, this, true);
+        cleanInOut(in, out);
+        throw error;
     }
-    else
+    catch (ast::ScilabMessage msg)
     {
-        Ret = Overload::call(L"%" + _paramL->getAs<List>()->getShortTypeStr() + L"_" + strType + L"_" + _paramR->getAs<List>()->getShortTypeStr(), in, 1, out, this, true);
+        cleanInOut(in, out);
+        throw msg;
     }
 
     if (Ret != Callable::OK)
index dfbf823..d402573 100644 (file)
@@ -370,6 +370,7 @@ void RunVisitorT<T>::visitprivate(const WhileExp  &e)
     InternalType* pIT = getResult();
     while (pIT->isTrue())
     {
+        pIT->killMe();
         e.getBody().accept(*this);
         if (e.getBody().isBreak())
         {
@@ -398,7 +399,6 @@ void RunVisitorT<T>::visitprivate(const WhileExp  &e)
             getResult()->killMe();
         }
 
-        pIT->killMe();
         e.getTest().accept(*this);
         pIT = getResult();
     }
@@ -727,8 +727,16 @@ void RunVisitorT<T>::visitprivate(const SelectExp &e)
             e.getDefaultCase()->setReturnable();
         }
 
-        //default case
-        e.getDefaultCase()->accept(*this);
+        try
+        {
+            //default case
+            e.getDefaultCase()->accept(*this);
+        }
+        catch (ScilabMessage& sm)
+        {
+            pIT->killMe();
+            throw sm;
+        }
 
         if (e.isBreakable() && e.getDefaultCase()->isBreak())
         {
@@ -1143,6 +1151,7 @@ void RunVisitorT<T>::visitprivate(const FunctionDec & e)
         os_swprintf(pwstFuncName, 1024, L"%-24ls", e.getSymbol().getName().c_str());
         char* pstFuncName = wide_string_to_UTF8(pwstFuncName);
 
+
         sciprint(_("Warning : redefining function: %s. Use funcprot(0) to avoid this message"), pstFuncName);
         sciprint("\n");
         FREE(pstFuncName);
@@ -1156,6 +1165,7 @@ void RunVisitorT<T>::visitprivate(const FunctionDec & e)
         std::wstring wstError(pwstError);
         FREE(pstFuncName);
         FREE(pwstError);
+        delete pMacro;
         throw ScilabError(wstError, 999, e.getLocation());
     }
 
@@ -1238,24 +1248,39 @@ void RunVisitorT<T>::visitprivate(const ListExp &e)
     types::typed_list out;
 
     piStart->IncreaseRef();
-    piStep->IncreaseRef();
-    piEnd->IncreaseRef();
-
     in.push_back(piStart);
-    if (e.hasExplicitStep())
+
+    try
     {
-        // 1:2:4
-        //call overload %typeStart_b_typeEnd
-        in.push_back(piStep);
-        in.push_back(piEnd);
-        Ret = Overload::call(L"%" + piStart->getShortTypeStr() + L"_b_" + piStep->getShortTypeStr(), in, 1, out, this, true);
+        if (e.hasExplicitStep())
+        {
+            // 1:2:4
+            //call overload %typeStart_b_typeStep
+            piStep->IncreaseRef();
+            in.push_back(piStep);
+            piEnd->IncreaseRef();
+            in.push_back(piEnd);
+            Ret = Overload::call(L"%" + piStart->getShortTypeStr() + L"_b_" + piStep->getShortTypeStr(), in, 1, out, this, true);
+        }
+        else
+        {
+            // 1:2
+            //call overload %typeStart_b_typeEnd
+            piStep->killMe();
+            piEnd->IncreaseRef();
+            in.push_back(piEnd);
+            Ret = Overload::call(L"%" + piStart->getShortTypeStr() + L"_b_" + piEnd->getShortTypeStr(), in, 1, out, this, true);
+        }
     }
-    else
+    catch (ScilabError& error)
     {
-        // 1:2
-        //call overload %typeStart_b_typeStep
-        in.push_back(piEnd);
-        Ret = Overload::call(L"%" + piStart->getShortTypeStr() + L"_b_" + piEnd->getShortTypeStr(), in, 1, out, this, true);
+        cleanInOut(in, out);
+        throw error;
+    }
+    catch (ast::ScilabMessage msg)
+    {
+        cleanInOut(in, out);
+        throw msg;
     }
 
     if (Ret != Callable::OK)
index 4aad8b1..021004a 100644 (file)
@@ -732,6 +732,7 @@ bool getFieldsFromExp(ast::Exp* _pExp, std::list<ExpHistory*>& fields)
             pCurrentArgs->clear();
             pCurrentArgs->push_back(pList->get(iListIncr));
             iListSize = pList->getSize();
+
         }
 
         do
@@ -777,12 +778,17 @@ bool getFieldsFromExp(ast::Exp* _pExp, std::list<ExpHistory*>& fields)
                 {
                     // create new args for next loop.
                     pCurrentArgs = new typed_list();
-                    pCurrentArgs->push_back(pList->get(iListIncr));
+                    pCurrentArgs->push_back(pList->get(iListIncr)->clone());
                 }
             }
         }
         while (iListIncr < iListSize);
 
+        if (bArgList)
+        {
+            pList->killMe();
+        }
+
         if (pCell)
         {
             // a{x}
@@ -997,11 +1003,12 @@ InternalType* evaluateFields(const ast::Exp* _pExp, std::list<ExpHistory*>& fiel
                         List* pList = pIT->getAs<List>();
                         double* pdblArgs = (*pArgs)[0]->getAs<Double>()->get();
 
+                        int listSize = pList->getSize();
                         if ((*iterFields)->getExp() == NULL)
                         {
                             // a(x)(y)
                             // extract a(x) and push_BACK to extract y
-                            for (int i = 0; i < pList->getSize(); i++)
+                            for (int i = 0; i < listSize; i++)
                             {
                                 ExpHistory* pEHExtract = new ExpHistory(pEH, NULL, (*iterFields)->getArgs(), (*iterFields)->getLevel(), (*iterFields)->isCellExp(), pList->get(i));
                                 pEHExtract->setWhereReinsert((int)(pdblArgs[i] - 1));
@@ -1012,13 +1019,16 @@ InternalType* evaluateFields(const ast::Exp* _pExp, std::list<ExpHistory*>& fiel
                         {
                             // a(x).b
                             // extract a(x) and push_FRONT to extract b
-                            for (int i = 0; i < pList->getSize(); i++)
+                            for (int i = 0; i < listSize; i++)
                             {
                                 ExpHistory* pEHExtract = new ExpHistory(pEH, pEH->getExp(), NULL, pEH->getLevel(), pEH->isCellExp(), pList->get(i));
                                 pEHExtract->setWhereReinsert((int)(pdblArgs[i] - 1));
                                 workFields.push_front(pEHExtract);
                             }
                         }
+
+                        //extract create a list to store items
+                        pList->killMe();
                     }
                 }
                 else
@@ -2102,6 +2112,7 @@ InternalType* insertionCall(const ast::Exp& e, typed_list* _pArgs, InternalType*
                                 {
                                     // set elements in the new position
                                     pStructInsert->get(i)->set(pwcsField, pLExtract->get(i));
+                                    pLExtract->get(i)->DecreaseRef();
                                 }
 
                                 pLExtract->killMe();
index 68ce30d..bd74679 100644 (file)
@@ -1342,6 +1342,7 @@ InternalType* add_I_M(T *_pL, U *_pR)
         add(dblLeft, pdblRight[index], pdblOut + index);
     }
 
+    delete[] piIndex;
     return pOut;
 }
 
@@ -1384,6 +1385,7 @@ InternalType* add_IC_M(T *_pL, U *_pR)
         add(_pR->get() + index, 1, _pL->get(0), _pL->getImg(0), pOut->get() + index, pOut->getImg() + index);
     }
 
+    delete[] piIndex;
     return pOut;
 }
 
@@ -1420,6 +1422,7 @@ InternalType* add_IC_MC(T *_pL, U *_pR)
         add(_pL->get(0), _pL->getImg(0), _pR->get(index), _pR->getImg(index), pOut->get() + index, pOut->getImg() + index);
     }
 
+    delete[] piIndex;
     return pOut;
 }
 
@@ -2225,6 +2228,8 @@ template<> InternalType* add_M_I<Polynom, Double, Polynom>(Polynom* _pL, Double*
             add(dblR, pSP[index]->get(0), pSP[index]->get());
         }
     }
+
+    delete[] piIndex;
     return pOut;
 }
 
@@ -2469,7 +2474,7 @@ template<> InternalType* add_M_M<Sparse, Double, Sparse>(Sparse* _pL, Double* _p
     if (_pR->isIdentity())
     {
         //convert to _pL
-        pOut = (Sparse*)_pL->clone();
+        pOut  = _pL->clone()->getAs<Sparse>();
         bool isComplex = _pL->isComplex() || _pR->isComplex();
         if (isComplex)
         {
index e601223..6087f40 100644 (file)
@@ -537,6 +537,13 @@ int RDivideSparseByDouble(types::Sparse* _pSp, types::Double* _pDouble, Internal
     }
     else
     {
+        for (int i = 0; i < iSize; ++i)
+        {
+            delete pDbl[i];
+            delete pDblSp[i];
+        }
+
+        delete[] pDbl;
         delete[] pDblSp;
         throw ast::ScilabError(_W("Invalid exponent.\n"));
         return 1;
@@ -554,15 +561,28 @@ int RDivideSparseByDouble(types::Sparse* _pSp, types::Double* _pDouble, Internal
             iResultat = RDivideDoubleByDouble(pDblSp[i], pDbl[i], &ppDblGet);
             if (iResultat != 0)
             {
+                delete ppDblGet;
                 return iResultat;
             }
             std::complex<double> cplx(ppDblGet->get(0), ppDblGet->getImg(0));
             pSpTemp->set(iPositVal[i], cplx, true);
+            delete ppDblGet;
         }
     }
+
     delete Col;
+    delete Row;
     delete iPositVal;
 
+    for (int i = 0; i < iSize; ++i)
+    {
+        delete pDbl[i];
+        delete pDblSp[i];
+    }
+
+    delete[] pDbl;
+    delete[] pDblSp;
+
     *_pSpOut = pSpTemp;
     return 0;
 }
index 7b257d4..7c2f584 100644 (file)
@@ -1289,32 +1289,35 @@ InternalType* dotdiv_M_M<Double, Sparse, Sparse>(Double* _pL, Sparse* _pR)
     //D -> SP / SP
     if (_pL->isScalar())
     {
-        Sparse* pOut = NULL;
+        Sparse* pTemp = NULL;
         int iSizeOut = _pR->getSize();
         if (_pL->isComplex())
         {
-            pOut = new Sparse(_pR->getRows(), _pR->getCols(), true);
+            pTemp = new Sparse(_pR->getRows(), _pR->getCols(), true);
             std::complex<double> stComplex(_pL->get(0), _pL->getImg(0));
             for (int i = 0 ; i < iSizeOut ; i++)
             {
                 if (_pR->get(i) != 0)
                 {
-                    pOut->set(i, stComplex);
+                    pTemp->set(i, stComplex);
                 }
             }
         }
         else
         {
-            pOut = new Sparse(_pR->getRows(), _pR->getCols(), _pR->isComplex());
+            pTemp = new Sparse(_pR->getRows(), _pR->getCols(), _pR->isComplex());
             for (int i = 0 ; i < iSizeOut ; i++)
             {
                 if (_pR->get(i) != 0)
                 {
-                    pOut->set(i, _pL->get(0));
+                    pTemp->set(i, _pL->get(0));
                 }
             }
         }
-        return pOut->dotDivide(*_pR);
+
+        Sparse* pOut = pTemp->dotDivide(*_pR);
+        delete pTemp;
+        return pOut;
     }
 
     if (_pR->isScalar())
@@ -1436,33 +1439,36 @@ InternalType* dotdiv_M_M<Sparse, Double, Sparse>(Sparse* _pL, Double* _pR)
     if (_pR->isScalar())
     {
         // SP / d-> SP
-        Sparse* pOut = NULL;
+        Sparse* pTemp = NULL;
         int iSizeOut = _pL->getSize();
         if (_pR->isComplex())
         {
-            pOut = new Sparse(_pL->getRows(), _pL->getCols(), true);
+            pTemp = new Sparse(_pL->getRows(), _pL->getCols(), true);
             std::complex<double> stComplex(_pR->get(0), _pR->getImg(0));
             for (int i = 0 ; i < iSizeOut ; i++)
             {
                 if (_pL->get(i) != 0)
                 {
-                    pOut->set(i, stComplex);
+                    pTemp->set(i, stComplex);
                 }
             }
         }
         else
         {
-            pOut = new Sparse(_pL->getRows(), _pL->getCols(), _pL->isComplex());
+            pTemp = new Sparse(_pL->getRows(), _pL->getCols(), _pL->isComplex());
             std::complex<double> stComplex(_pR->get(0), _pR->getImg(0));
             for (int i = 0 ; i < iSizeOut ; i++)
             {
                 if (_pL->get(i) != 0)
                 {
-                    pOut->set(i, _pR->get(0));
+                    pTemp->set(i, _pR->get(0));
                 }
             }
         }
-        return _pL->dotDivide(*pOut);
+
+        Sparse* pOut = _pL->dotDivide(*pTemp);
+        delete pTemp;
+        return pOut;
     }
 
     if (_pL->isScalar())
index 6b477f8..373f194 100644 (file)
@@ -1114,6 +1114,7 @@ InternalType* sub_I_M(T *_pL, U *_pR)
         sub(dblLeft, _pR->get(index), pOut->get() + index);
     }
 
+    delete[] piIndex;
     return pOut;
 }
 
@@ -1153,6 +1154,7 @@ InternalType* sub_I_MC(T *_pL, U *_pR)
         sub(dblLeft, pdblRight[index], pdblOut + index);
     }
 
+    delete[] piIndex;
     return pOut;
 }
 
@@ -1195,6 +1197,7 @@ InternalType* sub_IC_M(T *_pL, U *_pR)
         sub(&dblLeftR, &dblLeftI, (size_t)1, pdblRight[index], pdblOutR + index, pdblOutI + index);
     }
 
+    delete[] piIndex;
     return pOut;
 }
 
@@ -1236,6 +1239,7 @@ InternalType* sub_IC_MC(T *_pL, U *_pR)
         sub(dblLeftR, dblLeftI, pdblRightR[index], pdblRightI[index], pdblOutR + index, pdblOutI + index);
     }
 
+    delete[] piIndex;
     return pOut;
 }
 
@@ -1298,6 +1302,7 @@ template<class T, class U, class O> InternalType* sub_M_I(T *_pL, U *_pR)
         sub(pdblLeft[index], (size_t)1, &dblRight, pdblOutR + index);
     }
 
+    delete[] piIndex;
     return pOut;
 }
 
@@ -1344,6 +1349,7 @@ template<class T, class U, class O> InternalType* sub_M_IC(T *_pL, U *_pR)
         sub(pdblLeft[index], (size_t)1, &dblRightR, &dblRightI, pdblOutR + index, pdblOutI + index);
     }
 
+    delete[] piIndex;
     return pOut;
 }
 
@@ -1386,6 +1392,7 @@ template<class T, class U, class O> InternalType* sub_MC_IC(T *_pL, U *_pR)
         sub(pdblLeftR[index], pdblLeftI[index], (size_t)1, &dblRightR, &dblRightI, pdblOutR + index, pdblOutI + index);
     }
 
+    delete[] piIndex;
     return pOut;
 }
 
@@ -1804,6 +1811,8 @@ template<> InternalType* sub_M_M<Polynom, Double, Polynom>(Polynom* _pL, Double*
                 sub(pSPLeft[index]->get(0), (size_t)1, &dblRightR, pSPOut[index]->get());
             }
         }
+
+        delete[] piIndex;
         return pOut;
 
     }
@@ -1861,6 +1870,7 @@ template<> InternalType* sub_M_M<Polynom, Double, Polynom>(Polynom* _pL, Double*
                 pSPOut->get()[0] -= pdblR[i];
                 pSPOut->getImg()[0] -= pdblI[i];
                 pOut->set(i, pSPOut);
+                delete pSPOut;
             }
         }
         else
@@ -1873,6 +1883,7 @@ template<> InternalType* sub_M_M<Polynom, Double, Polynom>(Polynom* _pL, Double*
                 //update 0th rank value
                 pSPOut->get()[0] -= pdblR[i];
                 pOut->set(i, pSPOut);
+                delete pSPOut;
             }
         }
 
@@ -1984,6 +1995,7 @@ template<> InternalType* sub_I_M<Double, Polynom, Polynom>(Double* _pL, Polynom*
         sub(dblLeft, pSP[index]->get(0), pSPOut[index]->get());
     }
 
+    delete[] piIndex;
     return pOut;
 }
 
@@ -2022,6 +2034,7 @@ template<> InternalType* sub_I_MC<Double, Polynom, Polynom>(Double* _pL, Polynom
         sub(dblLeft, pSP[index]->get(0), pSPOut[index]->get());
     }
 
+    delete[] piIndex;
     return pOut;
 }
 
@@ -2062,6 +2075,7 @@ template<> InternalType* sub_IC_M<Double, Polynom, Polynom>(Double* _pL, Polynom
         sub(&dblLeftR, &dblLeftI, (size_t)1, pSP[index]->get(0), pSPOut[index]->get(), pSPOut[index]->getImg());
     }
 
+    delete[] piIndex;
     return pOut;
 }
 
@@ -2101,6 +2115,7 @@ template<> InternalType* sub_IC_MC<Double, Polynom, Polynom>(Double* _pL, Polyno
         sub(dblLeftR, dblLeftI, pSP[index]->get(0), pSP[index]->getImg(0), pSPOut[index]->get(), pSPOut[index]->getImg());
     }
 
+    delete[] piIndex;
     return pOut;
 }
 
index 004390e..29e7325 100644 (file)
@@ -307,8 +307,8 @@ bool Context::putInPreviousScope(Variable* _var, types::InternalType* _pIT)
         if (varStack.empty() == false)
         {
             (*varStack.top())[_var->getSymbol()] = _var;
-            varStack.push(list);
         }
+        varStack.push(list);
     }
     return true;
 }
index f476c33..69acd48 100644 (file)
@@ -22,6 +22,7 @@ extern "C"
 #include "sci_malloc.h"
 #include "elem_common.h"
 }
+
 /*
 ** Module List
 ** \{
@@ -48,12 +49,12 @@ std::list<std::wstring> ConfigVariable::getModuleList()
 */
 std::wstring ConfigVariable::m_SCIPath;
 
-void ConfigVariable::setSCIPath(std::wstring& _SCIPath)
+void ConfigVariable::setSCIPath(const std::wstring& _SCIPath)
 {
     m_SCIPath = _SCIPath;
 }
 
-std::wstring ConfigVariable::getSCIPath()
+std::wstring& ConfigVariable::getSCIPath()
 {
     return m_SCIPath;
 }
@@ -69,12 +70,12 @@ std::wstring ConfigVariable::getSCIPath()
 
 std::wstring ConfigVariable::m_SCIHOME;
 
-void ConfigVariable::setSCIHOME(std::wstring& _SCIHOME)
+void ConfigVariable::setSCIHOME(const std::wstring& _SCIHOME)
 {
     m_SCIHOME = _SCIHOME;
 }
 
-std::wstring ConfigVariable::getSCIHOME()
+std::wstring& ConfigVariable::getSCIHOME()
 {
     return m_SCIHOME;
 }
@@ -89,12 +90,12 @@ std::wstring ConfigVariable::getSCIHOME()
 
 std::wstring ConfigVariable::m_TMPDIR;
 
-void ConfigVariable::setTMPDIR(std::wstring& _TMPDIR)
+void ConfigVariable::setTMPDIR(const std::wstring& _TMPDIR)
 {
     m_TMPDIR = _TMPDIR;
 }
 
-std::wstring ConfigVariable::getTMPDIR()
+std::wstring& ConfigVariable::getTMPDIR()
 {
     return m_TMPDIR;
 }
@@ -259,12 +260,12 @@ bool ConfigVariable::getWarningMode(void)
 
 std::wstring ConfigVariable::m_HOME;
 
-void ConfigVariable::setHOME(std::wstring& _HOME)
+void ConfigVariable::setHOME(const std::wstring& _HOME)
 {
     m_HOME = _HOME;
 }
 
-std::wstring ConfigVariable::getHOME()
+std::wstring& ConfigVariable::getHOME()
 {
     return m_HOME;
 }
@@ -305,12 +306,12 @@ void ConfigVariable::clearLastError(void)
 
 std::wstring ConfigVariable::m_wstError;
 
-void ConfigVariable::setLastErrorMessage(std::wstring _wstError)
+void ConfigVariable::setLastErrorMessage(const std::wstring& _wstError)
 {
     m_wstError = _wstError;
 }
 
-std::wstring ConfigVariable::getLastErrorMessage()
+std::wstring& ConfigVariable::getLastErrorMessage()
 {
     return m_wstError;
 }
@@ -379,12 +380,12 @@ int ConfigVariable::getLastErrorLine(void)
 
 std::wstring ConfigVariable::m_wstErrorFunction;
 
-void ConfigVariable::setLastErrorFunction(std::wstring _wstErrorFunction)
+void ConfigVariable::setLastErrorFunction(const std::wstring& _wstErrorFunction)
 {
     m_wstErrorFunction = _wstErrorFunction;
 }
 
-std::wstring ConfigVariable::getLastErrorFunction()
+std::wstring& ConfigVariable::getLastErrorFunction()
 {
     return m_wstErrorFunction;
 }
@@ -621,7 +622,7 @@ std::list<ConfigVariable::EntryPointStr*> ConfigVariable::m_EntryPointList;
 ConfigVariable::DynamicLibraryStr* ConfigVariable::getNewDynamicLibraryStr()
 {
     DynamicLibraryStr* pDL = (DynamicLibraryStr*)MALLOC(sizeof(DynamicLibraryStr));
-    pDL->pwstLibraryName = NULL;
+    pDL->wstLibraryName = L"";
     pDL->hLib = 0;
     return pDL;
 }
@@ -632,31 +633,23 @@ ConfigVariable::EntryPointStr* ConfigVariable::getNewEntryPointStr()
     pEP->bOK = false;
     pEP->functionPtr = NULL;
     pEP->iLibIndex = -1;
-    pEP->pwstEntryPointName = NULL;
+    pEP->wstEntryPointName = L"";
     return pEP;
 }
 
-void ConfigVariable::setLibraryName(ConfigVariable::DynamicLibraryStr* _pDynamicLibrary, wchar_t* _pwstLibraryName)
+void ConfigVariable::setLibraryName(ConfigVariable::DynamicLibraryStr* _pDynamicLibrary, const std::wstring& _wstLibraryName)
 {
     if (_pDynamicLibrary)
     {
-        if (_pDynamicLibrary->pwstLibraryName)
-        {
-            FREE(_pDynamicLibrary->pwstLibraryName);
-        }
-        _pDynamicLibrary->pwstLibraryName = os_wcsdup(_pwstLibraryName);
+        _pDynamicLibrary->wstLibraryName = _wstLibraryName;
     }
 }
 
-void ConfigVariable::setEntryPointName(ConfigVariable::EntryPointStr* _pEntryPoint, wchar_t* _pwstEntryPointName)
+void ConfigVariable::setEntryPointName(ConfigVariable::EntryPointStr* _pEntryPoint, const std::wstring& _wstEntryPointName)
 {
     if (_pEntryPoint)
     {
-        if (_pEntryPoint->pwstEntryPointName)
-        {
-            FREE(_pEntryPoint->pwstEntryPointName);
-        }
-        _pEntryPoint->pwstEntryPointName = os_wcsdup(_pwstEntryPointName);;
+        _pEntryPoint->wstEntryPointName = _wstEntryPointName;
     }
 }
 
@@ -686,7 +679,9 @@ void ConfigVariable::removeDynamicLibrary(int _iDynamicLibraryIndex)
             //clear all entry points linked to removed dynamic library
             if ((*it)->iLibIndex == _iDynamicLibraryIndex)
             {
+                EntryPointStr* pEP = *it;
                 m_EntryPointList.remove(*it);
+                delete pEP;
                 if (m_EntryPointList.size() == 0)
                 {
                     break;
@@ -695,6 +690,7 @@ void ConfigVariable::removeDynamicLibrary(int _iDynamicLibraryIndex)
             }
         }
         //remove dynamic library
+        delete m_DynLibList[_iDynamicLibraryIndex];
         m_DynLibList[_iDynamicLibraryIndex] = NULL;
     }
 
@@ -734,7 +730,7 @@ void ConfigVariable::addEntryPoint(ConfigVariable::EntryPointStr* _pEP)
     }
 }
 
-ConfigVariable::EntryPointStr* ConfigVariable::getEntryPoint(wchar_t* _pwstEntryPointName, int _iDynamicLibraryIndex)
+ConfigVariable::EntryPointStr* ConfigVariable::getEntryPoint(const std::wstring& _wstEntryPointName, int _iDynamicLibraryIndex)
 {
     std::list<EntryPointStr*>::const_iterator it;
     for (it = m_EntryPointList.begin() ; it != m_EntryPointList.end() ; it++)
@@ -742,7 +738,7 @@ ConfigVariable::EntryPointStr* ConfigVariable::getEntryPoint(wchar_t* _pwstEntry
         //by pass iLibIndex check if _iDynamicLibraryIndex == -1
         if (_iDynamicLibraryIndex == -1 || (*it)->iLibIndex == _iDynamicLibraryIndex)
         {
-            if (wcscmp((*it)->pwstEntryPointName, _pwstEntryPointName) == 0)
+            if ((*it)->wstEntryPointName == _wstEntryPointName)
             {
                 return *it;
             }
@@ -765,7 +761,7 @@ dynlib_ptr ConfigVariable::getEntryPointFromPosition(int position)
     return NULL;
 }
 
-int ConfigVariable::getEntryPointPosition(wchar_t* _pwstEntryPointName, int _iDynamicLibraryIndex)
+int ConfigVariable::getEntryPointPosition(const std::wstring& _wstEntryPointName, int _iDynamicLibraryIndex)
 {
     int pos = 0;
     std::list<EntryPointStr*>::const_iterator it;
@@ -774,7 +770,7 @@ int ConfigVariable::getEntryPointPosition(wchar_t* _pwstEntryPointName, int _iDy
         //by pass iLibIndex check if _iDynamicLibraryIndex == -1
         if (_iDynamicLibraryIndex == -1 || (*it)->iLibIndex == _iDynamicLibraryIndex)
         {
-            if (wcscmp((*it)->pwstEntryPointName, _pwstEntryPointName) == 0)
+            if ((*it)->wstEntryPointName == _wstEntryPointName)
             {
                 return pos;
             }
@@ -789,7 +785,7 @@ std::vector<std::wstring> ConfigVariable::getEntryPointNameList()
     std::list<EntryPointStr*>::const_iterator it;
     for (it = m_EntryPointList.begin() ; it != m_EntryPointList.end() ; it++)
     {
-        EntryPointNames.push_back((*it)->pwstEntryPointName);
+        EntryPointNames.push_back((*it)->wstEntryPointName);
     }
     return EntryPointNames;
 }
@@ -1138,7 +1134,7 @@ int ConfigVariable::getMacroFirstLines()
 
 std::list<std::wstring> ConfigVariable::m_ReferenceModules;
 
-bool ConfigVariable::checkReferenceModule(std::wstring _module)
+bool ConfigVariable::checkReferenceModule(const std::wstring& _module)
 {
     for (auto ref : m_ReferenceModules)
     {
@@ -1151,7 +1147,7 @@ bool ConfigVariable::checkReferenceModule(std::wstring _module)
     return false;
 }
 
-void ConfigVariable::addReferenceModule(std::wstring _module)
+void ConfigVariable::addReferenceModule(const std::wstring& _module)
 {
     if (checkReferenceModule(_module) == false)
     {
@@ -1159,7 +1155,7 @@ void ConfigVariable::addReferenceModule(std::wstring _module)
     }
 }
 
-void ConfigVariable::removeReferenceModule(std::wstring _module)
+void ConfigVariable::removeReferenceModule(const std::wstring& _module)
 {
     if (checkReferenceModule(_module))
     {
index 2230bb1..d2fa898 100644 (file)
@@ -485,6 +485,10 @@ InternalType* ArrayOf<T>::insertNew(typed_list* _pArgs, InternalType* _pSource)
         //if all index are : -> a = x
         if (iCompteurNull == pArg.size())
         {
+            delete[] piMaxDim;
+            delete[] piCountDim;
+            //free pArg content
+            cleanIndexesArguments(_pArgs, &pArg);
             return _pSource;
         }
 
@@ -909,6 +913,10 @@ InternalType* ArrayOf<T>::extract(typed_list* _pArgs)
 
     if (iSeqCount < 0)
     {
+        delete[] piMaxDim;
+        delete[] piCountDim;
+        //free pArg content
+        cleanIndexesArguments(_pArgs, &pArg);
         return NULL;
     }
 
@@ -1249,7 +1257,7 @@ bool ArrayOf<T>::resize(int* _piDims, int _iDims)
     else
     {
         iNewSize = get_max_size(_piDims, _iDims);
-        if (m_iSizeMax < iNewSize)
+        if (iNewSize > m_iSizeMax)
         {
             //alloc 10% bigger than asked to prevent future resize
             int iOldSizeMax = m_iSizeMax;
@@ -1270,6 +1278,7 @@ bool ArrayOf<T>::resize(int* _piDims, int _iDims)
                 getIndexes(i, piIndexes);
                 int iNewIdx = getIndexWithDims(piIndexes, _piDims, _iDims);
                 pRealData[iNewIdx] = m_pRealData[i];
+                m_pRealData[i] = NULL;
                 for (int j = iPreviousNewIdx; j < iNewIdx; ++j)
                 {
                     T pTemp = getNullValue();
@@ -1284,22 +1293,28 @@ bool ArrayOf<T>::resize(int* _piDims, int _iDims)
                 iPreviousNewIdx = iNewIdx + 1;
             }
 
-            // if it's not the first resize,
-            // fill new data with element of last allocation
-            if (iPreviousNewIdx < iOldSizeMax)
+            //clean section between m_iSize and iOldSizeMax
+            for (int i = m_iSize; i < iOldSizeMax; ++i)
             {
-                for (int i = iPreviousNewIdx; i < iOldSizeMax; ++i)
-                {
-                    pRealData[i] = m_pRealData[i];
-                }
-            }
-            else
-            {
-                // first resize, iOldSizeMax don't contain the 10%
-                iOldSizeMax = iPreviousNewIdx;
+                deleteData(m_pRealData[i]);
+                m_pRealData[i] = NULL;
             }
 
-            for (int i = iOldSizeMax; i < m_iSizeMax; ++i)
+            //if (iPreviousNewIdx < iOldSizeMax)
+            //{
+            //    for (int i = iPreviousNewIdx; i < iOldSizeMax; ++i)
+            //    {
+            //        pRealData[i] = m_pRealData[i];
+            //        m_pRealData[i] = NULL;
+            //    }
+            //}
+            //else
+            //{
+            //    iOldSizeMax = iPreviousNewIdx;
+            //}
+
+            //fill exceeded with NullValue
+            for (int i = iPreviousNewIdx; i < m_iSizeMax; ++i)
             {
                 T pTemp = getNullValue();
                 T pTemp2 = copyValue(pTemp);
index 6c1e354..aac596e 100644 (file)
@@ -49,7 +49,7 @@ void Cell::createCell(int _iDims, int* _piDims)
 {
     InternalType** pIT = NULL;
     create(_piDims, _iDims, &pIT, NULL);
-    for (int i = 0; i < getSize(); i++)
+    for (int i = 0; i < m_iSizeMax; i++)
     {
         m_pRealData[i] = Double::Empty();
         m_pRealData[i]->IncreaseRef();
index 531c77c..45f0d14 100644 (file)
@@ -135,6 +135,7 @@ Double* Double::Identity(int _iDims, int* _piDims, double _dblReal, double _dblI
         int index = getIndexWithDims(piIndex, _piDims, _iDims);
         pI->set(index, _dblReal);
         pI->setImg(index, _dblImg);
+        delete[] piIndex;
     }
     return pI;
 }
index db3adf0..86ea023 100644 (file)
@@ -242,6 +242,7 @@ InternalType* List::insert(typed_list* _pArgs, InternalType* _pSource)
             InternalType* pIT = (*m_plData)[idx - 1];
             if (pIT)
             {
+                pIT->DecreaseRef();
                 pIT->killMe();
             }
             m_plData->erase(m_plData->begin() + idx - 1);
index 9d802b0..05213dc 100644 (file)
@@ -28,24 +28,24 @@ Polynom::Polynom()
 #endif
 }
 
-Polynom::Polynom(wstring _szVarName, int _iRows, int _iCols)
+Polynom::Polynom(wstring& _szVarName, int _iRows, int _iCols)
 {
     int piDims[2]   = {_iRows, _iCols};
     createPoly(_szVarName, 2, piDims, NULL);
 }
 
-Polynom::Polynom(wstring _szVarName, int _iRows, int _iCols, const int *_piRank)
+Polynom::Polynom(wstring& _szVarName, int _iRows, int _iCols, const int *_piRank)
 {
     int piDims[2]   = {_iRows, _iCols};
     createPoly(_szVarName, 2, piDims, _piRank);
 }
 
-Polynom::Polynom(std::wstring _szVarName, int _iDims, int* _piDims)
+Polynom::Polynom(wstring& _szVarName, int _iDims, int* _piDims)
 {
     createPoly(_szVarName, _iDims, _piDims, NULL);
 }
 
-Polynom::Polynom(std::wstring _szVarName, int _iDims, int* _piDims, const int *_piRank)
+Polynom::Polynom(wstring& _szVarName, int _iDims, int* _piDims, const int *_piRank)
 {
     createPoly(_szVarName, _iDims, _piDims, _piRank);
 }
@@ -61,7 +61,7 @@ Polynom::~Polynom()
 #endif
 }
 
-void Polynom::createPoly(std::wstring _szVarName, int _iDims, int* _piDims, const int *_piRank)
+void Polynom::createPoly(wstring& _szVarName, int _iDims, int* _piDims, const int *_piRank)
 {
     m_szVarName = _szVarName;
     SinglePoly** pPoly = NULL;
@@ -187,7 +187,7 @@ void Polynom::whoAmI(void)
     std::cout << "types::SinglePoly";
 }
 
-wstring Polynom::getVariableName()
+wstring& Polynom::getVariableName()
 {
     return m_szVarName;
 }
@@ -951,7 +951,7 @@ void Polynom::deleteAll()
 {
     for (int i = 0 ; i < m_iSizeMax ; i++)
     {
-        m_pRealData[i]->killMe();
+        delete m_pRealData[i];
     }
     delete[] m_pRealData;
     m_pRealData = NULL;
index 0b732aa..76b148a 100644 (file)
@@ -273,16 +273,25 @@ Sparse::~Sparse()
 {
     delete matrixReal;
     delete matrixCplx;
+#ifndef NDEBUG
+    Inspector::removeItem(this);
+#endif
 }
 
-Sparse::Sparse( Sparse const& src) : GenericType(src)
-    , matrixReal(src.matrixReal ? new RealSparse_t(*src.matrixReal) : 0)
+Sparse::Sparse(Sparse const& src)
+    : matrixReal(src.matrixReal ? new RealSparse_t(*src.matrixReal) : 0)
     , matrixCplx(src.matrixCplx ? new CplxSparse_t(*src.matrixCplx) : 0)
 
 {
+    m_iRows = const_cast<Sparse*>(&src)->getRows();
+    m_iCols = const_cast<Sparse*>(&src)->getCols();
+    m_iSize = m_iRows * m_iCols;
     m_iDims = 2;
-    m_piDims[0] = const_cast<Sparse*>(&src)->getRows();
-    m_piDims[1] = const_cast<Sparse*>(&src)->getCols();
+    m_piDims[0] = m_iRows;
+    m_piDims[1] = m_iCols;
+#ifndef NDEBUG
+    Inspector::addItem(this);
+#endif
 }
 
 Sparse::Sparse(int _iRows, int _iCols, bool cplx)
@@ -295,6 +304,9 @@ Sparse::Sparse(int _iRows, int _iCols, bool cplx)
     m_iDims = 2;
     m_piDims[0] = _iRows;
     m_piDims[1] = _iCols;
+#ifndef NDEBUG
+    Inspector::addItem(this);
+#endif
 }
 
 Sparse::Sparse(Double SPARSE_CONST& src)
@@ -311,6 +323,9 @@ Sparse::Sparse(Double SPARSE_CONST& src)
     }
     create2(src.getRows(), src.getCols(), src, *idx);
     idx->killMe();
+#ifndef NDEBUG
+    Inspector::addItem(this);
+#endif
 }
 
 Sparse::Sparse(Double SPARSE_CONST& src, Double SPARSE_CONST& idx)
@@ -320,11 +335,17 @@ Sparse::Sparse(Double SPARSE_CONST& src, Double SPARSE_CONST& idx)
     int cols = static_cast<int>(*std::max_element(idx.get() + idxrow, idx.get() + idxrow * 2));
 
     create2(rows, cols, src, idx);
+#ifndef NDEBUG
+    Inspector::removeItem(this);
+#endif
 }
 
 Sparse::Sparse(Double SPARSE_CONST& src, Double SPARSE_CONST& idx, Double SPARSE_CONST& dims)
 {
     create2(static_cast<int>(dims.get(0)), static_cast<int>(dims.get(1)), src, idx);
+#ifndef NDEBUG
+    Inspector::addItem(this);
+#endif
 }
 
 Sparse::Sparse(RealSparse_t* realSp, CplxSparse_t* cplxSp):  matrixReal(realSp), matrixCplx(cplxSp)
@@ -343,12 +364,18 @@ Sparse::Sparse(RealSparse_t* realSp, CplxSparse_t* cplxSp):  matrixReal(realSp),
     m_iDims = 2;
     m_piDims[0] = m_iRows;
     m_piDims[1] = m_iCols;
+#ifndef NDEBUG
+    Inspector::addItem(this);
+#endif
 }
 
 Sparse::Sparse(Double SPARSE_CONST& xadj, Double SPARSE_CONST& adjncy, Double SPARSE_CONST& src, std::size_t r, std::size_t c)
 {
     Adjacency a(xadj.get(), adjncy.get());
     create(static_cast<int>(r), static_cast<int>(c), src, makeIteratorFromVar(a), src.getSize());
+#ifndef NDEBUG
+    Inspector::addItem(this);
+#endif
 }
 
 template<typename DestIter>
@@ -1372,6 +1399,9 @@ Sparse* Sparse::remove(typed_list* _pArgs)
     {
         if (iNewDimSize == 0)
         {
+            delete[] piNewDims;
+            //free pArg content
+            cleanIndexesArguments(_pArgs, &pArg);
             return new Sparse(0, 0);
         }
         else
@@ -1503,11 +1533,19 @@ InternalType* Sparse::extract(typed_list* _pArgs)
         if (_pArgs->size() == 0)
         {
             //a()
+            delete[] piMaxDim;
+            delete[] piCountDim;
+            //free pArg content
+            cleanIndexesArguments(_pArgs, &pArg);
             return this;
         }
         else
         {
             //a([])
+            delete[] piMaxDim;
+            delete[] piCountDim;
+            //free pArg content
+            cleanIndexesArguments(_pArgs, &pArg);
             return Double::Empty();
         }
     }
@@ -2201,6 +2239,9 @@ SparseBool::SparseBool(Bool SPARSE_CONST& src)
     }
     create2(src.getRows(), src.getCols(), src, *idx);
     idx->killMe();
+#ifndef NDEBUG
+    Inspector::addItem(this);
+#endif
 }
 /* @param src : Bool matrix to copy into a new sparse matrix
 @param idx : Double matrix to use as indexes to get values from the src
@@ -2211,6 +2252,9 @@ SparseBool::SparseBool(Bool SPARSE_CONST& src, Double SPARSE_CONST& idx)
     int rows = static_cast<int>(*std::max_element(idx.get(), idx.get() + idxrow));
     int cols = static_cast<int>(*std::max_element(idx.get() + idxrow, idx.get() + idxrow * 2));
     create2(rows, cols, src, idx);
+#ifndef NDEBUG
+    Inspector::addItem(this);
+#endif
 }
 
 /* @param src : Bool matrix to copy into a new sparse matrix
@@ -2220,6 +2264,9 @@ SparseBool::SparseBool(Bool SPARSE_CONST& src, Double SPARSE_CONST& idx)
 SparseBool::SparseBool(Bool SPARSE_CONST& src, Double SPARSE_CONST& idx, Double SPARSE_CONST& dims)
 {
     create2(static_cast<int>(dims.get(0)), static_cast<int>(dims.get(1)), src, idx);
+#ifndef NDEBUG
+    Inspector::addItem(this);
+#endif
 }
 
 SparseBool::SparseBool(int _iRows, int _iCols) : matrixBool(new BoolSparse_t(_iRows, _iCols))
@@ -2230,9 +2277,12 @@ SparseBool::SparseBool(int _iRows, int _iCols) : matrixBool(new BoolSparse_t(_iR
     m_iDims = 2;
     m_piDims[0] = _iRows;
     m_piDims[1] = _iCols;
+#ifndef NDEBUG
+    Inspector::addItem(this);
+#endif
 }
 
-SparseBool::SparseBool(SparseBool const& src) : GenericType(src),  matrixBool(new BoolSparse_t(*src.matrixBool))
+SparseBool::SparseBool(SparseBool const& src) : matrixBool(new BoolSparse_t(*src.matrixBool))
 {
     m_iDims = 2;
     m_iRows = const_cast<SparseBool*>(&src)->getRows();
@@ -2240,6 +2290,9 @@ SparseBool::SparseBool(SparseBool const& src) : GenericType(src),  matrixBool(ne
     m_iSize = m_iRows * m_iCols;
     m_piDims[0] = m_iRows;
     m_piDims[1] = m_iCols;
+#ifndef NDEBUG
+    Inspector::addItem(this);
+#endif
 }
 
 SparseBool::SparseBool(BoolSparse_t* src) : matrixBool(src)
@@ -2250,6 +2303,9 @@ SparseBool::SparseBool(BoolSparse_t* src) : matrixBool(src)
     m_iDims = 2;
     m_piDims[0] = m_iRows;
     m_piDims[1] = m_iCols;
+#ifndef NDEBUG
+    Inspector::addItem(this);
+#endif
 }
 
 void SparseBool::create2(int rows, int cols, Bool SPARSE_CONST& src, Double SPARSE_CONST& idx)
@@ -2283,6 +2339,9 @@ void SparseBool::create2(int rows, int cols, Bool SPARSE_CONST& src, Double SPAR
 SparseBool::~SparseBool()
 {
     delete matrixBool;
+#ifndef NDEBUG
+    Inspector::removeItem(this);
+#endif
 }
 
 bool SparseBool::toString(std::wostringstream& ostr) const
index af2a68b..de5aab4 100644 (file)
@@ -564,7 +564,7 @@ void String::deleteData(wchar_t* data)
     if (data)
     {
         // data are always allocated using C-like malloc API
-        free(data);
+        FREE(data);
     }
 }
 
index f26678e..14de9c8 100644 (file)
@@ -120,11 +120,14 @@ bool Struct::transpose(InternalType *& out)
 
     if (m_iDims == 2)
     {
-        Struct * pSt = new Struct();
-        out = pSt;
-        SingleStruct** pSSt = NULL;
         int piDims[2] = {getCols(), getRows()};
-        pSt->create(piDims, 2, &pSSt, NULL);
+        Struct * pSt = new Struct(2, piDims);
+        out = pSt;
+        for (int i = 0; i < m_iSize; ++i)
+        {
+            pSt->m_pRealData[i]->DecreaseRef();
+            pSt->m_pRealData[i]->killMe();
+        }
 
         Transposition::transpose_clone(getRows(), getCols(), m_pRealData, pSt->m_pRealData);
 
@@ -558,6 +561,9 @@ std::vector<InternalType*> Struct::extractFields(typed_list* _pArgs)
     int* piCountDim     = new int[iDims];
 
     int iSeqCount = checkIndexesArguments(this, _pArgs, &pArg, piMaxDim, piCountDim);
+    delete[] piMaxDim;
+    delete[] piCountDim;
+
     if (iSeqCount == 0)
     {
         //free pArg content
index 5477a51..6fa1454 100644 (file)
@@ -284,6 +284,8 @@ int checkIndexesArguments(InternalType* _pRef, typed_list* _pArgsIn, typed_list*
             wchar_t szError[bsiz];
             os_swprintf(szError, bsiz, _W("Invalid index.\n").c_str());
 
+            delete[] _piMaxDim;
+            delete[] _piCountDim;
             cleanIndexesArguments(_pArgsIn, _pArgsOut);
 
             throw ast::ScilabError(szError);
index e8ded2e..b99af70 100644 (file)
@@ -4,9 +4,11 @@
 //
 //  This file is distributed under the same license as the Scilab package.
 // ============================================================================
+//
 // <-- JVM NOT MANDATORY -->
-// <-- ENGLISH IMPOSED -->
+//
 // Try to take all the branches in run_MatrixExp code...
+funcprot(0);
 a=[[] []; [] []];
 a=[1 2];
 a=[1;2];
@@ -15,11 +17,10 @@ a=[1 2;3 4];
 a=[1 2:4;5:7 3];
 a=[1 2:4 [];[] [] 5:7 [] 3];
 a=[1 2;sin(3) 4];
-assert_checkerror("a=[1 2;3 4 5]", "inconsistent row/column dimensions");
-assert_checkerror("a=[1 2;list(3) 4]", ["Undefined operation for the given operands." ; "check or define function %l_c_s for overloading."]);
+assert_checkerror("a=[1 2;3 4 5]", _("inconsistent row/column dimensions"));
+assert_checkerror("a=[1 2;list(3) 4]", msprintf(_("Undefined operation for the given operands.\n") + "%s", msprintf(_("check or define function %s for overloading.\n"), "%l_c_s")));
 function y=%l_c_s(l, x);y=[l(1)+1 x];end
 assert_checkequal([1 2;list(3) 4], [1 2;4 4]);
 function y=%l_c_s(l, x);y=[l(1) l(1) x];end
-Warning : redefining function: %l_c_s                  . Use funcprot(0) to avoid this message
 assert_checkerror("a=[1 2;list(3) 4]", "inconsistent row/column dimensions");
 a=[1 2 3; 7 sprand(1,2,0.5)];
index 02f2ff9..60081da 100644 (file)
@@ -4,12 +4,13 @@
 //
 //  This file is distributed under the same license as the Scilab package.
 // ============================================================================
-
+//
 // <-- JVM NOT MANDATORY -->
-// <-- ENGLISH IMPOSED -->
+//
 
 // Try to take all the branches in run_MatrixExp code...
 
+funcprot(0);
 a=[[] []; [] []];
 a=[1 2];
 a=[1;2];
@@ -18,11 +19,10 @@ a=[1 2;3 4];
 a=[1 2:4;5:7 3];
 a=[1 2:4 [];[] [] 5:7 [] 3];
 a=[1 2;sin(3) 4];
-assert_checkerror("a=[1 2;3 4 5]", "inconsistent row/column dimensions");
-assert_checkerror("a=[1 2;list(3) 4]", ["Undefined operation for the given operands." ; "check or define function %l_c_s for overloading."]);
+assert_checkerror("a=[1 2;3 4 5]", _("inconsistent row/column dimensions"));
+assert_checkerror("a=[1 2;list(3) 4]", msprintf(_("Undefined operation for the given operands.\n") + "%s", msprintf(_("check or define function %s for overloading.\n"), "%l_c_s")));
 function y=%l_c_s(l, x);y=[l(1)+1 x];end
 assert_checkequal([1 2;list(3) 4], [1 2;4 4]);
 function y=%l_c_s(l, x);y=[l(1) l(1) x];end
 assert_checkerror("a=[1 2;list(3) 4]", "inconsistent row/column dimensions");
 a=[1 2 3; 7 sprand(1,2,0.5)];
-
index c5f88a7..fd03261 100644 (file)
@@ -280,6 +280,11 @@ int StartScilabEngine(ScilabEngineInfo* _pSEI)
                 StoreConsoleCommand(_pSEI->pstExec);
             }
 
+            if (parser.getTree())
+            {
+                delete parser.getTree();
+                parser.setTree(NULL);
+            }
             iMainRet = ConfigVariable::getExitStatus();
         }
         else if (_pSEI->pstFile)
@@ -369,10 +374,9 @@ void StopScilabEngine(ScilabEngineInfo* _pSEI)
     symbol::Context::getInstance()->clearAll();
     //destroy context
     symbol::Context::destroyInstance();
-
 #ifndef NDEBUG
     //uncomment to print mem leak log
-    //types::Inspector::displayMemleak();
+    types::Inspector::displayMemleak();
 #endif
 
     // cleanup Java dependent features
@@ -605,7 +609,8 @@ void* scilabReadAndStore(void* param)
             parserErrorMsg = parser.getErrorMessage();
             if (parser.getTree())
             {
-                delete (parser.getTree());
+                delete parser.getTree();
+                parser.setTree(NULL);
             }
             ThreadManagement::UnlockParser();
         }
index e190989..b2efec1 100644 (file)
@@ -210,7 +210,7 @@ void displayDynLibInfo(void)
     {
         if (getIlibVerboseLevel() != ILIB_VERBOSE_NO_OUTPUT)
         {
-            sciprint(_("Entry point %ls in shared library %d.\n"), (*it)->pwstEntryPointName, (*it)->iLibIndex);
+            sciprint(_("Entry point %ls in shared library %d.\n"), (*it)->wstEntryPointName.c_str(), (*it)->iLibIndex);
         }
     }
 }
index 46f8c98..e22e0c9 100644 (file)
@@ -78,7 +78,7 @@ void unLink(int _iLib)
     ConfigVariable::DynamicLibraryStr* pStr = ConfigVariable::getDynamicLibrary(_iLib);
     if (pStr)
     {
-        DynLibHandle iLib = ConfigVariable::getDynamicLibrary(_iLib)->hLib;
+        DynLibHandle iLib = pStr->hLib;
         ConfigVariable::removeDynamicLibrary(_iLib);
         Sci_dlclose(iLib);
     }
index 2499bec..1a0daf0 100644 (file)
@@ -156,8 +156,8 @@ types::Function::ReturnValue sci_simp(types::typed_list &in, int _iRetCount, typ
 
                     if (iErr)
                     {
-                        delete pdblNumTmp;
-                        delete pdblDenTmp;
+                        delete[] pdblNumTmp;
+                        delete[] pdblDenTmp;
                         break;
                     }
 
@@ -170,13 +170,13 @@ types::Function::ReturnValue sci_simp(types::typed_list &in, int _iRetCount, typ
                     pPolyNumOut->set(i, pSPNum);
                     pPolyDenOut->set(i, pSPDen);
 
-                    delete pdblNumTmp;
-                    delete pdblDenTmp;
+                    delete[] pdblNumTmp;
+                    delete[] pdblDenTmp;
                     delete pSPNum;
                     delete pSPDen;
                 }
 
-                delete pdblWork;
+                delete[] pdblWork;
                 delete pNum;
                 delete pDen;
 
index 8703743..25249ff 100644 (file)
@@ -152,6 +152,7 @@ Function::ReturnValue sci_sparse(typed_list &in, int _piRetCount, typed_list &ou
             pDims = new Double(1, 2, false);
             pDims->set(0, *std::max_element(i, i + size));
             pDims->set(1, *std::max_element(j, j + size));
+            alloc = true;
         }
 
         if (in[1]->isDouble())