Coverity: ast module resource leaks fixed 89/18189/3
Dhruv Khattar [Fri, 27 May 2016 15:16:12 +0000 (20:16 +0530)]
Change-Id: I1e0ff623a838ae686bc7fd40b71bc0ad7a28e554

scilab/modules/ast/src/cpp/operations/types_divide.cpp
scilab/modules/ast/src/cpp/operations/types_power.cpp
scilab/modules/ast/src/cpp/system_env/home.cpp
scilab/modules/ast/src/cpp/system_env/sci_home.cpp
scilab/modules/ast/src/cpp/system_env/sci_path.cpp
scilab/modules/ast/src/cpp/system_env/sci_tmpdir.cpp
scilab/modules/ast/src/cpp/types/arrayof.cpp
scilab/modules/ast/src/cpp/types/function.cpp
scilab/modules/ast/src/cpp/types/implicitlist.cpp
scilab/modules/ast/src/cpp/types/sparse.cpp
scilab/modules/ast/src/cpp/types/string.cpp

index 51a1fce..7ca79dc 100644 (file)
@@ -557,6 +557,15 @@ int RDivideSparseByDouble(types::Sparse* _pSp, types::Double* _pDouble, Internal
             iResultat = RDivideDoubleByDouble(pDblSp[i], pDbl[i], &ppDblGet);
             if (iResultat != 0)
             {
+                for (int i = 0; i < iSize; ++i)
+                {
+                    delete pDbl[i];
+                    delete pDblSp[i];
+                }
+                delete[] pDbl;
+                delete[] pDblSp;
+                delete[] iPositVal;
+                delete pSpTemp;
                 delete ppDblGet;
                 return iResultat;
             }
index 1bdc70b..19019cf 100644 (file)
@@ -502,6 +502,7 @@ int DotPowerSpaseByDouble(Sparse* _pSp, Double* _pDouble, InternalType** _pOut)
     else
     {
         delete[] pDblSp;
+        delete[] pDbl;
         throw ast::InternalError(_W("Invalid exponent.\n"));
         return 1;
     }
@@ -523,6 +524,13 @@ int DotPowerSpaseByDouble(Sparse* _pSp, Double* _pDouble, InternalType** _pOut)
     delete[] Col;
     delete[] Row;
     delete[] iPositVal;
+    for (int i = 0; i < iSize; i++)
+    {
+        delete pDbl[i];
+        delete pDblSp[i];
+    }
+    delete pDbl;
+    delete pDblSp;
 
     pSpTemp->finalize();
     *_pOut = pSpTemp;
index 14c851a..d882874 100644 (file)
@@ -93,6 +93,7 @@ char* computeHOME(void)
             }
             else
             {
+                delete[] pstUserProfile;
                 return NULL;
             }
         }
index 0ad607e..b277d81 100644 (file)
@@ -225,6 +225,7 @@ char* getenvSCIHOME(void)
 
         if (ierr == 1)
         {
+            delete[] SciHome;
             return NULL;
         }
     }
index 8c6f8ad..51f5c0e 100644 (file)
@@ -144,6 +144,7 @@ char* getenvSCI()
 
         if (ierr == 1)
         {
+            delete[] SciPath;
             return NULL;
         }
     }
index 8e79e8d..78f467e 100644 (file)
@@ -118,6 +118,7 @@ char* getenvTMPDIR()
 
         if (ierr == 1)
         {
+            delete[] SciPath;
             return NULL;
         }
     }
index 2be57d5..63d4bd0 100644 (file)
@@ -772,6 +772,7 @@ GenericType* ArrayOf<T>::remove(typed_list* _pArgs)
         }
     }
 
+    delete[] pbFull;
 
     if (bTooMuchNotEntire == true)
     {
@@ -780,8 +781,6 @@ GenericType* ArrayOf<T>::remove(typed_list* _pArgs)
         return NULL;
     }
 
-    delete[] pbFull;
-
     //find index to keep
     int iNotEntireSize = pArg[iNotEntire]->getAs<GenericType>()->getSize();
     double* piNotEntireIndex = getDoubleArrayFromDouble(pArg[iNotEntire]);
index f5ade51..b07fdec 100644 (file)
@@ -652,6 +652,7 @@ Callable::ReturnValue DynamicFunction::Init()
         {
             char* pstLoadDepsName = wide_string_to_UTF8(m_wstLoadDepsName.c_str());
             m_pLoadDeps = (LOAD_DEPS)GetDynLibFuncPtr(hLib, pstLoadDepsName);
+            FREE(pstLoadDepsName);
         }
 
     }
index 91f8e57..eaf6695 100644 (file)
@@ -653,6 +653,7 @@ InternalType* ImplicitList::extract(typed_list* _pArgs)
     else
     {
         int* piDims = new int[iDims];
+        int* pIndex = new int[iDims];
         for (int i = 0 ; i < iDims ; i++)
         {
             piDims[i] = 1;
@@ -660,7 +661,6 @@ InternalType* ImplicitList::extract(typed_list* _pArgs)
 
         for (int i = 0 ; i < iSeqCount ; i++)
         {
-            int* pIndex = new int[iDims];
             for (int j = 0 ; j < iDims ; j++)
             {
                 Double* pDbl = pArg[j]->getAs<Double>();
@@ -669,6 +669,8 @@ InternalType* ImplicitList::extract(typed_list* _pArgs)
 
             index = getIndexWithDims(pIndex, piDims, iDims);
         }
+        delete[] pIndex;
+        delete[] piDims;
     }
 
     switch (index)
index 0b47fa5..2ea89ce 100644 (file)
@@ -1443,6 +1443,8 @@ GenericType* Sparse::remove(typed_list* _pArgs)
         }
     }
 
+    delete[] pbFull;
+
     if (bTooMuchNotEntire == true)
     {
         //free pArg content
@@ -1450,8 +1452,6 @@ GenericType* Sparse::remove(typed_list* _pArgs)
         return NULL;
     }
 
-    delete[] pbFull;
-
     //find index to keep
     int iNotEntireSize          = pArg[iNotEntire]->getAs<GenericType>()->getSize();
     double* piNotEntireIndex    = getDoubleArrayFromDouble(pArg[iNotEntire]);
@@ -3344,6 +3344,8 @@ GenericType* SparseBool::remove(typed_list* _pArgs)
         }
     }
 
+    delete[] pbFull;
+
     if (bTooMuchNotEntire == true)
     {
         //free pArg content
@@ -3351,8 +3353,6 @@ GenericType* SparseBool::remove(typed_list* _pArgs)
         return NULL;
     }
 
-    delete[] pbFull;
-
     //find index to keep
     int iNotEntireSize          = pArg[iNotEntire]->getAs<GenericType>()->getSize();
     double* piNotEntireIndex    = getDoubleArrayFromDouble(pArg[iNotEntire]);
index 91e8f64..d74c4f9 100644 (file)
@@ -365,6 +365,7 @@ bool String::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i
                         ostr << ostemp.str();
                         m_iRows2PrintState = iRows2;
                         m_iCols1PrintState = iLastCol;
+                        delete[] piSize;
                         return false;
                     }
 
@@ -442,6 +443,7 @@ bool String::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i
                 ostr << ostemp.str();
                 m_iRows2PrintState = iRows2;
                 m_iCols1PrintState = iLastCol;
+                delete[] piSize;
                 return false;
             }
 
@@ -504,6 +506,7 @@ bool String::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_i
             addColumnString(ostr, iLastCol + 1, getCols());
         }
         ostr << ostemp.str();
+        delete[] piSize;
     }
 
     return true;