Coverity #1321058, #1321094, #1321156, #1354293 fixed 03/18503/3
Dhruv Khattar [Sun, 21 Aug 2016 10:10:32 +0000 (15:10 +0530)]
Change-Id: I83391d3b60fed8b56dbd219219a39ec5fa4169e2

scilab/modules/matio/src/c/CreateDoubleVariable.c
scilab/modules/matio/src/c/CreateSparseVariable.c
scilab/modules/matio/src/cpp/CreateMatlabTreeVariable.cpp
scilab/modules/matio/src/cpp/CreateStructVariable.cpp

index c8eb479..7f4acea 100644 (file)
@@ -74,16 +74,8 @@ int CreateDoubleVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
             piDims[i] = (int)matVariable->dims[i];
         }
 
-        if (matVariable->isComplex == 0)
-        {
-            CreateHyperMatrixVariable(pvApiCtx, iVar, matVariable->class_type, &matVariable->isComplex, &matVariable->rank,
-                                      piDims, matVariable, parent, item_position);
-        }
-        else
-        {
-            CreateHyperMatrixVariable(pvApiCtx, iVar, matVariable->class_type, &matVariable->isComplex, &matVariable->rank,
-                                      piDims, matVariable, parent, item_position);
-        }
+        CreateHyperMatrixVariable(pvApiCtx, iVar, matVariable->class_type, &matVariable->isComplex, &matVariable->rank,
+                                  piDims, matVariable, parent, item_position);
 
         FREE(piDims);
     }
index 92b99d5..520909b 100644 (file)
@@ -159,8 +159,8 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
         {
             Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
             FREE(scilabSparse);
-            FREE(scilabSparseT);
             FREE(scilabSparseT->mnel);
+            FREE(scilabSparseT);
             FREE(workArray);
             FREE(colIndexes);
             FREE(rowIndexes);
@@ -175,9 +175,9 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
         {
             Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
             FREE(scilabSparse);
-            FREE(scilabSparseT);
             FREE(scilabSparseT->icol);
             FREE(scilabSparseT->mnel);
+            FREE(scilabSparseT);
             FREE(workArray);
             FREE(colIndexes);
             FREE(rowIndexes);
@@ -192,10 +192,10 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
         {
             Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
             FREE(scilabSparse);
-            FREE(scilabSparseT);
             FREE(scilabSparseT->icol);
             FREE(scilabSparseT->mnel);
             FREE(scilabSparseT->R);
+            FREE(scilabSparseT);
             FREE(workArray);
             FREE(colIndexes);
             FREE(rowIndexes);
@@ -217,13 +217,13 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
             {
                 printError(&sciErr, 0);
                 FREE(scilabSparse);
-                FREE(scilabSparseT);
                 FREE(workArray);
                 FREE(colIndexes);
                 FREE(rowIndexes);
                 FREE(scilabSparseT->icol);
                 FREE(scilabSparseT->mnel);
                 FREE(scilabSparseT->R);
+                FREE(scilabSparseT);
                 return 0;
             }
         }
@@ -236,13 +236,13 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
             {
                 printError(&sciErr, 0);
                 FREE(scilabSparse);
-                FREE(scilabSparseT);
                 FREE(workArray);
                 FREE(colIndexes);
                 FREE(rowIndexes);
                 FREE(scilabSparseT->icol);
                 FREE(scilabSparseT->mnel);
                 FREE(scilabSparseT->R);
+                FREE(scilabSparseT);
                 return 0;
             }
         }
@@ -257,13 +257,13 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
             {
                 printError(&sciErr, 0);
                 FREE(scilabSparse);
-                FREE(scilabSparseT);
                 FREE(workArray);
                 FREE(colIndexes);
                 FREE(rowIndexes);
                 FREE(scilabSparseT->icol);
                 FREE(scilabSparseT->mnel);
                 FREE(scilabSparseT->R);
+                FREE(scilabSparseT);
                 return 0;
             }
         }
@@ -276,13 +276,13 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
             {
                 printError(&sciErr, 0);
                 FREE(scilabSparse);
-                FREE(scilabSparseT);
                 FREE(workArray);
                 FREE(colIndexes);
                 FREE(rowIndexes);
                 FREE(scilabSparseT->icol);
                 FREE(scilabSparseT->mnel);
                 FREE(scilabSparseT->R);
+                FREE(scilabSparseT);
                 return 0;
             }
         }
index 0dbd7fa..13348c3 100644 (file)
@@ -27,6 +27,7 @@ extern "C"
 #include "CreateMatlabVariable.h"
 #include "api_scilab.h"
 #include "Scierror.h"
+#include "sci_malloc.h"
 }
 
 types::InternalType* CreateMatlabTreeVariable(matvar_t *matVariable)
@@ -98,7 +99,7 @@ types::InternalType* CreateMatlabTreeVariable(matvar_t *matVariable)
             {
                 pOut = new types::Struct(iRank, piDims);
                 int iSizeStruct = Mat_VarGetNumberOfFields(matVariable);
-
+                wchar_t* temp;
                 matvar_t** allData = (matvar_t**)(matVariable->data);
 
                 bool bSearchSizeStruck = false;
@@ -112,7 +113,9 @@ types::InternalType* CreateMatlabTreeVariable(matvar_t *matVariable)
                             break;
                         }
                     }
-                    std::wstring wstField(to_wide_string((char*)allData[i]->name));
+                    temp = to_wide_string((char*)allData[i]->name);
+                    std::wstring wstField(temp);
+                    FREE(temp);
                     pOut->getAs<types::Struct>()->addField(wstField);
                 }
 
@@ -120,7 +123,9 @@ types::InternalType* CreateMatlabTreeVariable(matvar_t *matVariable)
                 {
                     for (int j = 0; j < iSizeStruct; j++)
                     {
-                        std::wstring wstField(to_wide_string((char*)allData[j]->name));
+                        temp = to_wide_string((char*)allData[j]->name);
+                        std::wstring wstField(temp);
+                        FREE(temp);
                         pOut->getAs<types::Struct>()->get(i)->set(wstField, CreateMatlabTreeVariable(allData[i * iSizeStruct + j]));
                     }
                 }
index dd6a8a4..d664f8d 100644 (file)
@@ -60,10 +60,13 @@ int CreateStructVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
 
     matvar_t** allData = (matvar_t**)(matVariable->data);
 
+    wchar_t* temp;
     int iSizeStruct = Mat_VarGetNumberOfFields(matVariable);
     for (int i = 0; i < iSizeStruct; i++)
     {
-        std::wstring wstField(to_wide_string((char*)allData[i]->name));
+        temp = to_wide_string((char*)allData[i]->name);
+        std::wstring wstField(temp);
+        FREE(temp);
         pStruct->addField(wstField);
     }
 
@@ -71,7 +74,9 @@ int CreateStructVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
     {
         for (int j = 0; j < iSizeStruct; j++)
         {
-            std::wstring wstField(to_wide_string((char*)allData[j]->name));
+            temp = to_wide_string((char*)allData[j]->name);
+            std::wstring wstField(temp);
+            FREE(temp);
             pStruct->get(i)->set(wstField, CreateMatlabTreeVariable(allData[i * iSizeStruct + j]));
         }
     }