Coverity: Optimization module Resource Leaks fixed 41/18141/4
Dhruv Khattar [Fri, 6 May 2016 08:37:26 +0000 (13:37 +0530)]
Change-Id: Ic2b676cdd181505f442e1e14c1db59d50e5c949c

scilab/modules/optimization/sci_gateway/cpp/sci_fsolve.cpp
scilab/modules/optimization/sci_gateway/cpp/sci_lsqrsolve.cpp
scilab/modules/optimization/sci_gateway/cpp/sci_optim.cpp
scilab/modules/optimization/sci_gateway/cpp/sci_readmps.cpp
scilab/modules/optimization/sci_gateway/cpp/sci_semidef.cpp

index 04c61ec..7303a52 100644 (file)
@@ -193,6 +193,7 @@ types::Function::ReturnValue sci_fsolve(types::typed_list &in, int _iRetCount, t
                 if (bOK == false)
                 {
                     Scierror(50, _("%s: Subroutine not found: %s\n"), "fsolve", pst);
+                    FREE(pst);
                     return types::Function::Error;
                 }
 
index fa63b39..356d01c 100644 (file)
@@ -233,6 +233,7 @@ types::Function::ReturnValue sci_lsqrsolve(types::typed_list &in, int _iRetCount
                 if (bOK == false)
                 {
                     Scierror(50, _("%s: Subroutine not found: %s\n"), "lsqrsolve", pst);
+                    FREE(pst);
                     return types::Function::Error;
                 }
 
index ca1049c..69f980a 100644 (file)
@@ -487,6 +487,8 @@ types::Function::ReturnValue sci_optim(types::typed_list &in, types::optional_li
             if (iSizeX0 > 46333)
             {
                 Scierror(999, _("Can not allocate %.2f MB memory.\n"), (double)(iWorkSize * sizeof(double)) / 1.e6);
+                delete[] pdblG;
+                delete[] pdblX0;
                 return types::Function::Error;
             }
             try
@@ -502,6 +504,8 @@ types::Function::ReturnValue sci_optim(types::typed_list &in, types::optional_li
             catch (std::bad_alloc& /*ba*/)
             {
                 Scierror(999, _("Can not allocate %.2f MB memory.\n"), (double)(iWorkSize * sizeof(double)) / 1.e6);
+                delete[] pdblG;
+                delete[] pdblX0;
                 return types::Function::Error;
             }
         }
index 3235c49..17e8308 100644 (file)
@@ -58,8 +58,6 @@ types::Function::ReturnValue sci_readmps(types::typed_list &in, int _iRetCount,
     char typrow[2];
 
     wchar_t* wcsFileName = NULL;
-    char* strErrorBuf = new char[bsiz];
-
     double big = NumericConstants::double_max;
 
     if (in.size() < 2 || in.size() > 3)
@@ -187,6 +185,7 @@ types::Function::ReturnValue sci_readmps(types::typed_list &in, int _iRetCount,
     pstrRwName[8 * iM] = '\0';
     char* pstrClName = new char[8 * iN + 1];
     pstrClName[8 * iN] = '\0';
+    char* strErrorBuf = new char[bsiz];
 
     int irobj       = 0;
     int* piStavar   = new int[iN];
index 24284f8..c73ca3b 100644 (file)
@@ -127,11 +127,6 @@ types::Function::ReturnValue sci_semidef(types::typed_list &in, int _iRetCount,
 
     double* pdblB = pDblB->get();
     iSizeB = pDblB->getSize();
-    piB = new int[iSizeB];
-    for (int i = 0; i < iSizeB; i++)
-    {
-        piB[i] = (int)pdblB[i];
-    }
 
     // get C
     if (in[4]->isDouble() == false)
@@ -190,6 +185,11 @@ types::Function::ReturnValue sci_semidef(types::typed_list &in, int _iRetCount,
     int sz      = 0;
     int upsz    = 0;
     int maxn    = 0;
+    piB = new int[iSizeB];
+    for (int i = 0; i < iSizeB; i++)
+    {
+        piB[i] = (int)pdblB[i];
+    }
 
     for (int i = 0; i < iSizeB; i++)
     {
@@ -211,6 +211,7 @@ types::Function::ReturnValue sci_semidef(types::typed_list &in, int _iRetCount,
 
     delete[] pdblWork;
     delete[] piWork;
+    delete[] piB;
 
     if (iInfo < 0)
     {