[elementary_functions] memory leak fixed 24/19524/2
Cedric Delamarre [Tue, 31 Oct 2017 14:46:38 +0000 (15:46 +0100)]
test_run("elementary_functions", ["iscolumn", "isempty", "ismatrix", "isrow", "isscalar", "issquare", "members", "bug_7649"])
test_run("elementary_functions", ["iscolumn", "isempty", "ismatrix", "isrow", "isscalar", "issquare", "members", "bug_7649"], "mode_nwni_profiling")

Change-Id: I7fbf45fefbe614a3657a2be74ad44c74ae8c4da2

scilab/modules/ast/src/cpp/ast/run_CallExp.hpp
scilab/modules/ast/src/cpp/ast/visitor_common.cpp
scilab/modules/ast/src/cpp/types/arrayof.cpp
scilab/modules/ast/src/cpp/types/cell.cpp

index 89333db..ac551d8 100644 (file)
@@ -131,6 +131,7 @@ void RunVisitorT<T>::visitprivate(const CallExp &e)
     }
     catch (ScilabException &)
     {
+        cleanIn(inTmp, outTmp);
         CoverageInstance::stopChrono((void*)&e);
         throw;
     }
@@ -142,6 +143,7 @@ void RunVisitorT<T>::visitprivate(const CallExp &e)
     if(pIT == NULL)
     {
         clearResult();
+        cleanIn(inTmp, outTmp);
         std::wostringstream os;
         os << _W("Cannot extract from nothing.") << std::endl;
         CoverageInstance::stopChrono((void*)&e);
@@ -156,6 +158,7 @@ void RunVisitorT<T>::visitprivate(const CallExp &e)
     if (pIT->getInvokeNbOut() != -1 && pIT->getInvokeNbOut() < iRetCount)
     {
         clearResult();
+        cleanIn(inTmp, outTmp);
         std::wostringstream os;
         os << _W("Wrong number of output arguments.\n") << std::endl;
         CoverageInstance::stopChrono((void*)&e);
index de9e957..e186c92 100644 (file)
@@ -468,6 +468,12 @@ types::InternalType* AddElementToVariable(types::InternalType* _poDest, types::I
             default:
                 break;
         }
+
+        if(poResult && isNew)
+        {
+            poResult->killMe();
+        }
+
         // call overload
         return NULL;
     }
@@ -534,8 +540,15 @@ types::InternalType* AddElementToVariable(types::InternalType* _poDest, types::I
                 poResult->getAs<types::GraphicHandle>()->append(iCurRow, iCurCol, _poSource);
                 break;
             default:
+            {
+                if(poResult && isNew)
+                {
+                    poResult->killMe();
+                }
+
                 // call overload
                 return NULL;
+            }
         }
         return poResult;
     }
index c6955b1..447c700 100644 (file)
@@ -758,6 +758,7 @@ ArrayOf<T>* ArrayOf<T>::append(int _iRows, int _iCols, InternalType* _poSource)
         return pIT;
     }
 
+    _poSource->IncreaseRef();
     ArrayOf * pGT = _poSource->getAs<ArrayOf>();
     int iRows = pGT->getRows();
     int iCols = pGT->getCols();
@@ -775,7 +776,7 @@ ArrayOf<T>* ArrayOf<T>::append(int _iRows, int _iCols, InternalType* _poSource)
     }
     else if (isComplex())
     {
-        pGT->setComplex(true);
+        pGT = pGT->setComplex(true);
     }
 
     if (pGT->isComplex())
@@ -800,6 +801,9 @@ ArrayOf<T>* ArrayOf<T>::append(int _iRows, int _iCols, InternalType* _poSource)
         }
     }
 
+    pGT->killMe();
+    _poSource->DecreaseRef();
+
     return this;
 }
 
index fbbf614..1ee2d04 100644 (file)
@@ -54,6 +54,11 @@ void Cell::createCell(int _iDims, const int* _piDims, InternalType** data)
 {
     InternalType** pIT = NULL;
     create(_piDims, _iDims, &pIT, NULL);
+    if( m_iSizeMax == 0)
+    {
+        return;
+    }
+
     if (data == nullptr)
     {
         types::Double* pDbl = Double::Empty();