Coverity: Matio module memory leaks fixed 32/18032/10
Aashish Misraa [Sun, 3 Apr 2016 11:25:50 +0000 (16:25 +0530)]
Change-Id: I1a7bff674f903bcf42c2208e04753c41b46270e2

18 files changed:
scilab/modules/api_scilab/src/cpp/api_stack_boolean.cpp
scilab/modules/api_scilab/src/cpp/api_stack_double.cpp
scilab/modules/localization/src/c/charEncoding.c
scilab/modules/matio/sci_gateway/c/sci_matfile_listvar.c
scilab/modules/matio/sci_gateway/c/sci_matfile_open.c
scilab/modules/matio/sci_gateway/c/sci_matfile_varwrite.c
scilab/modules/matio/src/c/CreateBooleanVariable.c
scilab/modules/matio/src/c/CreateCharVariable.c
scilab/modules/matio/src/c/CreateIntegerVariable.c
scilab/modules/matio/src/c/CreateSparseVariable.c
scilab/modules/matio/src/cpp/CreateCellVariable.cpp
scilab/modules/matio/src/cpp/CreateMatlabTreeVariable.cpp
scilab/modules/matio/src/cpp/CreateStructVariable.cpp
scilab/modules/matio/src/cpp/GetCellVariable.cpp
scilab/modules/matio/src/cpp/GetCharVariable.cpp
scilab/modules/matio/src/cpp/GetIntegerVariable.cpp
scilab/modules/matio/src/cpp/GetSparseVariable.cpp
scilab/modules/matio/src/cpp/GetStructVariable.cpp

index 45546ea..bf7306f 100644 (file)
@@ -95,6 +95,7 @@ SciErr allocMatrixOfBoolean(void* _pvCtx, int _iVar, int _iRows, int _iCols, int
     if (*_piBool == NULL)
     {
         addErrorMessage(&sciErr, API_ERROR_NO_MORE_MEMORY, _("%s: No more memory to allocated variable"), "allocMatrixOfBoolean");
+        delete[] pBool;
         return sciErr;
     }
 
index dff198d..500bb7c 100644 (file)
@@ -267,6 +267,7 @@ SciErr allocCommonMatrixOfDouble(void* _pvCtx, int _iVar, char _cType, int _iCom
     if (*_pdblReal == NULL)
     {
         addErrorMessage(&sciErr, API_ERROR_NO_MORE_MEMORY, _("%s: No more memory to allocate variable"), _iComplex ? "allocComplexMatrixOfDouble" : "allocexMatrixOfDouble");
+        delete pDbl;
         return sciErr;
     }
 
@@ -276,10 +277,11 @@ SciErr allocCommonMatrixOfDouble(void* _pvCtx, int _iVar, char _cType, int _iCom
         if (*_pdblImg == NULL)
         {
             addErrorMessage(&sciErr, API_ERROR_NO_MORE_MEMORY, _("%s: No more memory to allocate variable"), _iComplex ? "allocComplexMatrixOfDouble" : "allocMatrixOfDouble");
+            delete pDbl;
             return sciErr;
         }
     }
-
+    
     return sciErr;
 }
 
index 00211b4..f186dfa 100644 (file)
@@ -267,10 +267,10 @@ wchar_t *to_wide_string(const char *_UTFStr)
         iconv_close(cd_ISO8851_to_UTF16);
         if (iSize == (size_t)(-1))
         {
+            FREE(pOut);
             return NULL;
         }
     }
-
     return pOutSave;
 }
 /*--------------------------------------------------------------------------*/
index 1688dda..448cddf 100644 (file)
@@ -96,6 +96,8 @@ int sci_matfile_listvar(char *fname, void* pvApiCtx)
         if (varnames == NULL)
         {
             Scierror(999, _("%s: No more memory.\n"), "matfile_listvar");
+            FREE(varclasses);
+            FREE(vartypes);
             return FALSE;
         }
         varnames[nbvar - 1] = os_strdup(matvar->name);
@@ -103,6 +105,8 @@ int sci_matfile_listvar(char *fname, void* pvApiCtx)
         if (varclasses  == NULL)
         {
             Scierror(999, _("%s: No more memory.\n"), "matfile_listvar");
+            FREE(vartypes);
+            FREE(varnames);
             return FALSE;
         }
         varclasses[nbvar - 1] = (double) matvar->class_type;
@@ -110,6 +114,8 @@ int sci_matfile_listvar(char *fname, void* pvApiCtx)
         if (vartypes == NULL)
         {
             Scierror(999, _("%s: No more memory.\n"), "matfile_listvar");
+            FREE(varnames);
+            FREE(varclasses);
             return FALSE;
         }
         vartypes[nbvar - 1] = (double) matvar->data_type;
index 43a5b9c..89ac385 100644 (file)
@@ -58,11 +58,15 @@ int sci_matfile_open(char *fname, void* pvApiCtx)
 
     if (var_type == sci_strings)
     {
-        getAllocatedSingleString(pvApiCtx, filename_addr, &filename);
+        if (getAllocatedSingleString(pvApiCtx, filename_addr, &filename) != 0)
+        {
+            return 0;
+        }
         sciErr = getVarDimension(pvApiCtx, filename_addr, &nbRow, &nbCol);
         if (sciErr.iErr)
         {
             printError(&sciErr, 0);
+            freeAllocatedSingleString(filename);
             return 0;
         }
 
@@ -86,6 +90,7 @@ int sci_matfile_open(char *fname, void* pvApiCtx)
         if (sciErr.iErr)
         {
             printError(&sciErr, 0);
+            freeAllocatedSingleString(filename);
             return 0;
         }
 
@@ -93,16 +98,23 @@ int sci_matfile_open(char *fname, void* pvApiCtx)
         if (sciErr.iErr)
         {
             printError(&sciErr, 0);
+            freeAllocatedSingleString(filename);
             return 0;
         }
 
         if (var_type == sci_strings)
         {
-            getAllocatedSingleString(pvApiCtx, option_addr, &optionStr);
+            if (getAllocatedSingleString(pvApiCtx, option_addr, &optionStr) != 0)
+            {
+                freeAllocatedSingleString(filename);
+                return 0;
+            }
             sciErr = getVarDimension(pvApiCtx, option_addr, &nbRow, &nbCol);
             if (sciErr.iErr)
             {
                 printError(&sciErr, 0);
+                freeAllocatedSingleString(filename);
+                freeAllocatedSingleString(optionStr);
                 return 0;
             }
 
@@ -153,6 +165,8 @@ int sci_matfile_open(char *fname, void* pvApiCtx)
         if (sciErr.iErr)
         {
             printError(&sciErr, 0);
+            freeAllocatedSingleString(filename);
+            freeAllocatedSingleString(optionStr);
             return 0;
         }
 
@@ -160,16 +174,26 @@ int sci_matfile_open(char *fname, void* pvApiCtx)
         if (sciErr.iErr)
         {
             printError(&sciErr, 0);
+            freeAllocatedSingleString(filename);
+            freeAllocatedSingleString(optionStr);
             return 0;
         }
         printf("sci_strings %d %d\n", var_type, sci_strings);
         if (var_type == sci_strings)
         {
-            getAllocatedSingleString(pvApiCtx, version_addr, &versionStr);
+            if (getAllocatedSingleString(pvApiCtx, version_addr, &versionStr) != 0)
+            {
+                freeAllocatedSingleString(filename);
+                freeAllocatedSingleString(optionStr);
+                return 0;
+            }
             sciErr = getVarDimension(pvApiCtx, version_addr, &nbRow, &nbCol);
             if (sciErr.iErr)
             {
                 printError(&sciErr, 0);
+                freeAllocatedSingleString(filename);
+                freeAllocatedSingleString(optionStr);
+                freeAllocatedSingleString(versionStr);
                 return 0;
             }
             if (nbCol != 1)
@@ -194,6 +218,8 @@ int sci_matfile_open(char *fname, void* pvApiCtx)
         else
         {
             Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 3);
+            freeAllocatedSingleString(filename);
+            freeAllocatedSingleString(optionStr);
             return 0;
         }
     }
index d5391f8..015713e 100644 (file)
@@ -92,11 +92,15 @@ int sci_matfile_varwrite(char *fname, void* pvApiCtx)
 
     if (var_type == sci_strings)
     {
-        getAllocatedSingleString(pvApiCtx, name_addr, &varname);
+        if (getAllocatedSingleString(pvApiCtx, name_addr, &varname) != 0)
+        {
+            return 0;
+        }
         sciErr = getVarDimension(pvApiCtx, name_addr, &nbRow, &nbCol);
         if (sciErr.iErr)
         {
             printError(&sciErr, 0);
+            freeAllocatedSingleString(varname);
             return 0;
         }
         if (nbCol != 1)
index cba3ece..8d1a18c 100644 (file)
@@ -54,6 +54,7 @@ int CreateBooleanVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
                 if (sciErr.iErr)
                 {
                     printError(&sciErr, 0);
+                    FREE(intPtr);
                     return 0;
                 }
             }
@@ -63,6 +64,7 @@ int CreateBooleanVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
                 if (sciErr.iErr)
                 {
                     printError(&sciErr, 0);
+                    FREE(intPtr);
                     return 0;
                 }
             }
@@ -88,6 +90,7 @@ int CreateBooleanVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
                 if (sciErr.iErr)
                 {
                     printError(&sciErr, 0);
+                    FREE(dblPtr);
                     return 0;
                 }
             }
@@ -97,6 +100,7 @@ int CreateBooleanVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
                 if (sciErr.iErr)
                 {
                     printError(&sciErr, 0);
+                    FREE(dblPtr);
                     return 0;
                 }
             }
index 05c6746..edd0c47 100644 (file)
@@ -47,10 +47,11 @@ int CreateCharVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int * pa
 
         for (K = 0; K < nbRow; K++)
         {
-            charData[K] =  (char*) MALLOC(sizeof(char*) * (matVariable->dims[1] + 1));
+            charData[K] =  (char*) MALLOC(sizeof(char) * (matVariable->dims[1] + 1));
             if (charData[K] == NULL)
             {
                 Scierror(999, _("%s: No more memory.\n"), "CreateCharVariable");
+                freeArrayOfString(charData, K);
                 return FALSE;
             }
         }
@@ -73,6 +74,7 @@ int CreateCharVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int * pa
                 if (sciErr.iErr)
                 {
                     printError(&sciErr, 0);
+                    freeArrayOfString(charData, nbRow);
                     return 0;
                 }
             }
@@ -82,6 +84,7 @@ int CreateCharVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int * pa
                 if (sciErr.iErr)
                 {
                     printError(&sciErr, 0);
+                    freeArrayOfString(charData, nbRow);
                     return 0;
                 }
             }
@@ -100,6 +103,7 @@ int CreateCharVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int * pa
                 if (sciErr.iErr)
                 {
                     printError(&sciErr, 0);
+                    freeArrayOfString(tmp_char, 1);
                     return 0;
                 }
                 freeArrayOfString(tmp_char, 1);
index 215c286..427735e 100644 (file)
@@ -87,6 +87,7 @@ int CreateIntegerVariable(void *pvApiCtx, int iVar, int integerType, matvar_t *m
                 if (sciErr.iErr)
                 {
                     printError(&sciErr, 0);
+                    FREE(tmp_int8);
                     return 0;
                 }
 
@@ -121,6 +122,7 @@ int CreateIntegerVariable(void *pvApiCtx, int iVar, int integerType, matvar_t *m
                 if (sciErr.iErr)
                 {
                     printError(&sciErr, 0);
+                    FREE(tmp_int16);
                     return 0;
                 }
 
@@ -156,6 +158,7 @@ int CreateIntegerVariable(void *pvApiCtx, int iVar, int integerType, matvar_t *m
                 if (sciErr.iErr)
                 {
                     printError(&sciErr, 0);
+                    FREE(tmp_int32);
                     return 0;
                 }
 
@@ -190,6 +193,7 @@ int CreateIntegerVariable(void *pvApiCtx, int iVar, int integerType, matvar_t *m
                 if (sciErr.iErr)
                 {
                     printError(&sciErr, 0);
+                    FREE(tmp_int64);
                     return 0;
                 }
 
@@ -224,6 +228,7 @@ int CreateIntegerVariable(void *pvApiCtx, int iVar, int integerType, matvar_t *m
                 if (sciErr.iErr)
                 {
                     printError(&sciErr, 0);
+                    FREE(tmp_uint8);
                     return 0;
                 }
 
@@ -256,6 +261,7 @@ int CreateIntegerVariable(void *pvApiCtx, int iVar, int integerType, matvar_t *m
                 if (sciErr.iErr)
                 {
                     printError(&sciErr, 0);
+                    FREE(tmp_uint16);
                     return 0;
                 }
 
@@ -288,6 +294,7 @@ int CreateIntegerVariable(void *pvApiCtx, int iVar, int integerType, matvar_t *m
                 if (sciErr.iErr)
                 {
                     printError(&sciErr, 0);
+                    FREE(tmp_uint32);
                     return 0;
                 }
 
@@ -320,6 +327,7 @@ int CreateIntegerVariable(void *pvApiCtx, int iVar, int integerType, matvar_t *m
                 if (sciErr.iErr)
                 {
                     printError(&sciErr, 0);
+                    FREE(tmp_uint64);
                     return 0;
                 }
 
index 26d9c5c..92b99d5 100644 (file)
@@ -55,6 +55,7 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
         if (colIndexes == NULL)
         {
             Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+            FREE(scilabSparse);
             return FALSE;
         }
 
@@ -69,6 +70,8 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
     if (rowIndexes == NULL)
     {
         Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+        FREE(scilabSparse);
+        FREE(colIndexes);
         return FALSE;
     }
 
@@ -102,6 +105,9 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
     if (scilabSparseT == NULL)
     {
         Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+        FREE(scilabSparse);
+        FREE(colIndexes);
+        FREE(rowIndexes);
         return FALSE;
     }
 
@@ -109,6 +115,8 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
     scilabSparseT->n   = scilabSparse->m;
     scilabSparseT->it  = scilabSparse->it;
     scilabSparseT->nel = scilabSparse->nel;
+    scilabSparseT->mnel = NULL;
+    scilabSparseT->icol = NULL;
 
     if (scilabSparseT->m == 0)
     {
@@ -122,6 +130,10 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
     if (workArray == NULL)
     {
         Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+        FREE(scilabSparse);
+        FREE(scilabSparseT);
+        FREE(rowIndexes);
+        FREE(colIndexes);
         return FALSE;
     }
 
@@ -131,6 +143,11 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
         if (scilabSparseT->mnel == NULL)
         {
             Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+            FREE(scilabSparse);
+            FREE(scilabSparseT);
+            FREE(workArray);
+            FREE(colIndexes);
+            FREE(rowIndexes);
             return FALSE;
         }
     }
@@ -141,6 +158,12 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
         if (scilabSparseT->icol == NULL)
         {
             Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+            FREE(scilabSparse);
+            FREE(scilabSparseT);
+            FREE(scilabSparseT->mnel);
+            FREE(workArray);
+            FREE(colIndexes);
+            FREE(rowIndexes);
             return FALSE;
         }
     }
@@ -151,6 +174,13 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
         if (scilabSparseT->R == NULL)
         {
             Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+            FREE(scilabSparse);
+            FREE(scilabSparseT);
+            FREE(scilabSparseT->icol);
+            FREE(scilabSparseT->mnel);
+            FREE(workArray);
+            FREE(colIndexes);
+            FREE(rowIndexes);
             return FALSE;
         }
     }
@@ -161,6 +191,14 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
         if (scilabSparseT->I == NULL)
         {
             Scierror(999, _("%s: No more memory.\n"), "CreateSparseVariable");
+            FREE(scilabSparse);
+            FREE(scilabSparseT);
+            FREE(scilabSparseT->icol);
+            FREE(scilabSparseT->mnel);
+            FREE(scilabSparseT->R);
+            FREE(workArray);
+            FREE(colIndexes);
+            FREE(rowIndexes);
             return FALSE;
         }
     }
@@ -178,6 +216,14 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
             if (sciErr.iErr)
             {
                 printError(&sciErr, 0);
+                FREE(scilabSparse);
+                FREE(scilabSparseT);
+                FREE(workArray);
+                FREE(colIndexes);
+                FREE(rowIndexes);
+                FREE(scilabSparseT->icol);
+                FREE(scilabSparseT->mnel);
+                FREE(scilabSparseT->R);
                 return 0;
             }
         }
@@ -189,6 +235,14 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
             if (sciErr.iErr)
             {
                 printError(&sciErr, 0);
+                FREE(scilabSparse);
+                FREE(scilabSparseT);
+                FREE(workArray);
+                FREE(colIndexes);
+                FREE(rowIndexes);
+                FREE(scilabSparseT->icol);
+                FREE(scilabSparseT->mnel);
+                FREE(scilabSparseT->R);
                 return 0;
             }
         }
@@ -202,6 +256,14 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
             if (sciErr.iErr)
             {
                 printError(&sciErr, 0);
+                FREE(scilabSparse);
+                FREE(scilabSparseT);
+                FREE(workArray);
+                FREE(colIndexes);
+                FREE(rowIndexes);
+                FREE(scilabSparseT->icol);
+                FREE(scilabSparseT->mnel);
+                FREE(scilabSparseT->R);
                 return 0;
             }
         }
@@ -213,6 +275,14 @@ int CreateSparseVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
             if (sciErr.iErr)
             {
                 printError(&sciErr, 0);
+                FREE(scilabSparse);
+                FREE(scilabSparseT);
+                FREE(workArray);
+                FREE(colIndexes);
+                FREE(rowIndexes);
+                FREE(scilabSparseT->icol);
+                FREE(scilabSparseT->mnel);
+                FREE(scilabSparseT->R);
                 return 0;
             }
         }
index d808068..387f84e 100644 (file)
@@ -51,6 +51,7 @@ int CreateCellVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int * pa
     {
         types::Cell* pCell = new types::Cell();
         out[rhs - 1] = pCell;
+        FREE(piDims);
         return TRUE;
     }
 
index 46df25f..0dbd7fa 100644 (file)
@@ -57,6 +57,11 @@ types::InternalType* CreateMatlabTreeVariable(matvar_t *matVariable)
         }
     }
 
+    if (!piDims)
+    {
+        return types::Double::Empty();
+    }
+
     switch (matVariable->class_type)
     {
         case MAT_C_CELL: /* 1 */
@@ -130,6 +135,7 @@ types::InternalType* CreateMatlabTreeVariable(matvar_t *matVariable)
             strncat(pChar, (char*)matVariable->data, piDims[1]);
             types::String* pString = new types::String(pChar);
             pOut = pString;
+            FREE(pChar);
         }
         break;
         case MAT_C_SPARSE: /* 5 */
@@ -147,6 +153,8 @@ types::InternalType* CreateMatlabTreeVariable(matvar_t *matVariable)
                 if (colIndexes == NULL)
                 {
                     Scierror(999, _("%s: No more memory.\n"), "CreateMatlabTreeVariable");
+                    delete pSparse;
+                    FREE(piDims);
                     return NULL;
                 }
 
@@ -161,6 +169,9 @@ types::InternalType* CreateMatlabTreeVariable(matvar_t *matVariable)
             if (rowIndexes == NULL)
             {
                 Scierror(999, _("%s: No more memory.\n"), "CreateMatlabTreeVariable");
+                delete pSparse;
+                FREE(colIndexes);
+                FREE(piDims);
                 return NULL;
             }
 
@@ -310,13 +321,9 @@ types::InternalType* CreateMatlabTreeVariable(matvar_t *matVariable)
         case MAT_C_FUNCTION: /* 16 to be written */
         default:
             /* Empty matrix returned */
+            FREE(piDims);
             return types::Double::Empty();
     }
-
-    if (iRank != 0)
-    {
-        FREE(piDims);
-    }
-
+    FREE(piDims);
     return pOut;
 }
index 484f2a4..dd6a8a4 100644 (file)
@@ -52,6 +52,7 @@ int CreateStructVariable(void *pvApiCtx, int iVar, matvar_t *matVariable, int *
     {
         types::Struct* pStruct = new types::Struct();
         out[rhs - 1] = pStruct;
+        FREE(piDims);
         return TRUE;
     }
 
index a36333e..5446f97 100644 (file)
@@ -73,6 +73,7 @@ matvar_t* GetCellMatVar(types::Cell* pCell, const char* name, int matfile_versio
     if (cellEntries == NULL)
     {
         Scierror(999, _("%s: No more memory.\n"), "GetCellMatVar");
+        FREE(pszDims);
         return NULL;
     }
 
index 16d6f6a..31875b2 100644 (file)
@@ -102,6 +102,7 @@ matvar_t* GetCharMatVar(types::String* pStr, const char* name)
         char** ppcName = (char**)MALLOC(sizeof(char*) * pDims[0] * pDims[1]);
         if (ppcName == NULL)
         {
+            FREE(psize_t);
             Scierror(999, _("%s: No more memory.\n"), "GetCharMatVar");
             return NULL;
         }
@@ -110,14 +111,15 @@ matvar_t* GetCharMatVar(types::String* pStr, const char* name)
         if (pstMatData == NULL)
         {
             FREE(ppcName);
+            FREE(psize_t);
             Scierror(999, _("%s: No more memory.\n"), "GetCharMatVar");
             return NULL;
         }
-
+        
         for (int i = 0; i < pDims[0]; ++i)
         {
             ppcName[i] = wide_string_to_UTF8(pStr->get(i));
-            if (pstMatData == NULL)
+            if (ppcName[i] == NULL)
             {
                 for (int idelete = 0; idelete < i; ++idelete)
                 {
@@ -125,12 +127,12 @@ matvar_t* GetCharMatVar(types::String* pStr, const char* name)
                 }
                 FREE(ppcName);
                 FREE(pstMatData);
+                FREE(psize_t);
                 Scierror(999, _("%s: No more memory.\n"), "GetCharMatVar");
                 return NULL;
             }
         }
 
-
         for (int i = 0; i < pDims[0]; ++i)
         {
             for (int j = 0; j < iLen; ++j)
index b7f1e20..1816603 100644 (file)
@@ -111,8 +111,8 @@ matvar_t* GetIntegerMatVar(types::InternalType* pITIn, const char *name)
 #endif
         default:
             Scierror(999, _("%s: Wrong type for input argument #%d: Integer matrix expected.\n"), "GetIntegerMatVar", 1);
+            FREE(psize_t);
             return NULL;
-            break;
     }
 
     FREE(psize_t);
index dd113a5..a867d5b 100644 (file)
@@ -70,6 +70,8 @@ matvar_t* GetSparseMatVar(types::Sparse* pSparse, const char *name)
     {
         FREE(sparseData);
         Scierror(999, _("%s: No more memory.\n"), "GetSparseMatVar");
+        delete[] colPos;
+        delete[] itemsRow;
         return NULL;
     }
 
@@ -85,6 +87,8 @@ matvar_t* GetSparseMatVar(types::Sparse* pSparse, const char *name)
     {
         FREE(sparseData);
         FREE(colIndexes);
+        delete[] colPos;
+        delete[] itemsRow;
         Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
         return NULL;
     }
@@ -118,20 +122,20 @@ matvar_t* GetSparseMatVar(types::Sparse* pSparse, const char *name)
     }
 
     psize_t = (size_t*)MALLOC(Dims * sizeof(size_t));
-    if (rowIndexes == NULL)
+    if (psize_t == NULL)
     {
         FREE(sparseData);
         FREE(rowIndexes);
         FREE(colIndexes);
+        delete[] itemsRow;
+        delete[] colPos;
+        delete[] iPositVal;
         Scierror(999, _("%s: No more memory.\n"), "GetSparseVariable");
         return NULL;
     }
-
     psize_t[0] = (int)pDims[1];
     psize_t[1] = (int)pDims[0];
 
-
-
     if (pSparse->isComplex())
     {
         struct mat_complex_split_t* data;
@@ -143,6 +147,9 @@ matvar_t* GetSparseMatVar(types::Sparse* pSparse, const char *name)
             FREE(sparseData);
             FREE(colIndexes);
             FREE(rowIndexes);
+            delete[] itemsRow;
+            delete[] colPos;
+            delete[] iPositVal;
             Scierror(999, _("%s: No more memory.\n"), "GetSparseMatVar");
             return NULL;
         }
@@ -154,6 +161,9 @@ matvar_t* GetSparseMatVar(types::Sparse* pSparse, const char *name)
             FREE(sparseData);
             FREE(colIndexes);
             FREE(rowIndexes);
+            delete[] itemsRow;
+            delete[] colPos;
+            delete[] iPositVal;
             Scierror(999, _("%s: No more memory.\n"), "GetSparseMatVar");
             return NULL;
         }
@@ -166,6 +176,9 @@ matvar_t* GetSparseMatVar(types::Sparse* pSparse, const char *name)
             FREE(sparseData);
             FREE(colIndexes);
             FREE(rowIndexes);
+            delete[] itemsRow;
+            delete[] colPos;
+            delete[] iPositVal;
             Scierror(999, _("%s: No more memory.\n"), "GetSparseMatVar");
             return NULL;
         }
@@ -195,6 +208,9 @@ matvar_t* GetSparseMatVar(types::Sparse* pSparse, const char *name)
             FREE(sparseData);
             FREE(colIndexes);
             FREE(rowIndexes);
+            delete[] itemsRow;
+            delete[] colPos;
+            delete[] iPositVal;
             Scierror(999, _("%s: No more memory.\n"), "GetSparseMatVar");
             return NULL;
         }
@@ -211,5 +227,8 @@ matvar_t* GetSparseMatVar(types::Sparse* pSparse, const char *name)
     }
 
     FREE(psize_t);
+    delete[] iPositVal;
+    delete[] colPos;
+    delete[] itemsRow;
     return pMatVarOut;
 }
index 96dc072..da8354e 100644 (file)
@@ -76,6 +76,7 @@ matvar_t* GetStructMatVar(types::Struct* pStruct, const char *name, int matfile_
     if (structEntries == NULL)
     {
         Scierror(999, _("%s: No more memory.\n"), "GetStructMatVar");
+        FREE(pszDims);
         return NULL;
     }