[ast] memory leak fixed on ImplicitList and Cell 33/21233/3
Cedric Delamarre [Fri, 17 Jan 2020 16:12:47 +0000 (17:12 +0100)]
  test_run ast bug_16089 mode_nwni_profiling
  test_run ast bug_16200 mode_nwni_profiling

Change-Id: Iecffea0e7d4b43101acdd2d51e328754d3f30857

scilab/modules/ast/src/cpp/ast/runvisitor.cpp
scilab/modules/ast/src/cpp/types/cell.cpp
scilab/modules/ast/src/cpp/types/implicitlist.cpp

index 458f119..2ae6d1c 100644 (file)
@@ -128,7 +128,7 @@ void RunVisitorT<T>::visitprivate(const SimpleVar & e)
             ostr << std::endl;
             if (ConfigVariable::isPrintCompact() == false)
             {
-                ostr << std::endl;                
+                ostr << std::endl;
             }
             scilabWriteW(ostr.str().c_str());
             std::wostringstream ostrName;
@@ -1577,7 +1577,19 @@ void RunVisitorT<T>::visitprivate(const ListExp &e)
             (pEnd->isPoly() || pEnd->isDouble()))
     {
         // No need to kill piStart, ... because Implicit list ctor will incref them
-        setResult(new types::ImplicitList(pStart, pStep, pEnd));
+        types::ImplicitList* pIL = new types::ImplicitList(pStart, pStep, pEnd);
+        try
+        {
+            pIL->compute();
+        }
+        catch (const InternalError& ie)
+        {
+            // happends when compute() of ImplicitList cannot allocate memory
+            pIL->killMe();
+            throw ie;
+        }
+
+        setResult(pIL);
         CoverageInstance::stopChrono((void*)&e);
         return;
     }
@@ -1593,7 +1605,19 @@ void RunVisitorT<T>::visitprivate(const ListExp &e)
                  pStep->isDouble()))
         {
             // No need to kill piStart, ... because Implicit list ctor will incref them
-            setResult(new types::ImplicitList(pStart, pStep, pEnd));
+            types::ImplicitList* pIL = new types::ImplicitList(pStart, pStep, pEnd);
+            try
+            {
+                pIL->compute();
+            }
+            catch (const InternalError& ie)
+            {
+                // happends when compute() of ImplicitList cannot allocate memory
+                pIL->killMe();
+                throw ie;
+            }
+
+            setResult(pIL);
             CoverageInstance::stopChrono((void*)&e);
             return;
         }
index b4a6b6c..62469a6 100644 (file)
@@ -149,21 +149,16 @@ bool Cell::transpose(InternalType *& out)
 
     if (m_iDims == 2)
     {
-        Cell * pC = new Cell();
+        Cell * pC = new Cell(getCols(), getRows());
         out = pC;
-        InternalType** pIT = NULL;
-        int piDims[2] = {getCols(), getRows()};
-        pC->create(piDims, 2, &pIT, NULL);
-
         for (int i = 0, k = 0; i < getCols(); i++, k += getRows())
         {
             for (int j = 0, l = 0; j < getRows(); j++, l += getCols())
             {
-                pC->m_pRealData[i + l] = m_pRealData[j + k]->clone();
-                pC->m_pRealData[i + l]->IncreaseRef();
+                pC->set(i + l, m_pRealData[j + k]);
             }
         }
-     
+
         return true;
     }
 
index 7354f0f..527cdfd 100644 (file)
@@ -107,7 +107,7 @@ ImplicitList::ImplicitList(InternalType* _poStart, InternalType* _poStep, Intern
     setStart(_poStart);
     setStep(_poStep);
     setEnd(_poEnd);
-    compute();
+
 #ifndef NDEBUG
     Inspector::addItem(this);
 #endif