fix memory leaks 81/12781/4
Antoine ELIAS [Wed, 2 Oct 2013 09:09:00 +0000 (11:09 +0200)]
Coverity ID :
    - 1100076
    - 1099540 -> 1099544

Change-Id: I92218d687a0bf847f8f10e5c1d1bf4a2df834ac2

scilab/modules/core/sci_gateway/c/sci_what.c
scilab/modules/fileio/src/c/copyfile_others.c
scilab/modules/fileio/src/c/dlManager.c
scilab/modules/mpi/src/c/serialization.c
scilab/modules/string/sci_gateway/c/sci_length.c

index 943fc33..cc85374 100644 (file)
@@ -36,9 +36,6 @@ static int cmpfunctionnames( const void *a , const void *b);
 /*--------------------------------------------------------------------------*/
 int C2F(sci_what)(char *fname, unsigned long fname_len)
 {
-    int sizecommandwords = 0;
-    char **commandwords = getcommandkeywords(&sizecommandwords);
-
     Rhs = Max(0, Rhs);
     CheckRhs(0, 0);
     CheckLhs(1, 2);
@@ -54,6 +51,8 @@ int C2F(sci_what)(char *fname, unsigned long fname_len)
     }
     else /* Lhs == 2 */
     {
+        int sizecommandwords = 0;
+        char **commandwords = getcommandkeywords(&sizecommandwords);
         int ncol = 1;
         int nrowFunctions = SizeLocalFunctionsTab;
         int nrowCommands = sizecommandwords;
index e6bdfc4..6d72f4f 100644 (file)
@@ -207,6 +207,12 @@ static int CopyDirectoryFunction_others(wchar_t *DestinationDirectory, wchar_t *
                 FREE(pStrDest);
                 pStrDest = NULL;
             }
+
+            if (pStrSrc)
+            {
+                FREE(pStrSrc);
+                pStrSrc = NULL;
+            }
             return ENOTDIR;
         }
         else
@@ -218,26 +224,19 @@ static int CopyDirectoryFunction_others(wchar_t *DestinationDirectory, wchar_t *
                     FREE(pStrDest);
                     pStrDest = NULL;
                 }
+
+                if (pStrSrc)
+                {
+                    FREE(pStrSrc);
+                    pStrSrc = NULL;
+                }
+
                 return ENOTDIR;
             }
         }
     }
 
     ierr = RecursiveCopyDirectory(pStrDest, pStrSrc);
-    if (ierr)
-    {
-        if (pStrDest)
-        {
-            FREE(pStrDest);
-            pStrDest = NULL;
-        }
-        if (pStrSrc)
-        {
-            FREE(pStrSrc);
-            pStrSrc = NULL;
-        }
-        return errno;
-    }
     if (pStrDest)
     {
         FREE(pStrDest);
@@ -248,6 +247,12 @@ static int CopyDirectoryFunction_others(wchar_t *DestinationDirectory, wchar_t *
         FREE(pStrSrc);
         pStrSrc = NULL;
     }
+
+    if (ierr)
+    {
+        return errno;
+    }
+
     return 0;
 }
 /*--------------------------------------------------------------------------*/
index 7a6c38d..e870fe3 100644 (file)
@@ -152,10 +152,11 @@ int getProxyValues(char **proxyHost, long *proxyPort, char **proxyUserPwd)
     lSize = ftell(pFile);
     if (lSize < 0)
     {
-        FREE(configPtr);
         Scierror(999, _("Could not read the configuration file '%s'.\n"), configPtr);
+        FREE(configPtr);
         return 0;
     }
+
     rewind (pFile);
 
     // allocate memory to contain the whole file
index 2925f57..664a9b9 100644 (file)
@@ -157,6 +157,8 @@ static int serialize_string(void *_pvCtx, int *_piAddr, int **_piBuffer, int *_p
 
     *_piBuffer = piOut;
     *_piBufferSize = iOutLen;
+
+    freeAllocatedMatrixOfString(iRows, iCols, pstData);
     return 0;
 }
 
@@ -312,11 +314,13 @@ static int serialize_int(void *_pvCtx, int *_piAddr, int **_piBuffer, int *_piBu
                 break;
                 }
         */ default:
+            FREE(piOut);
             return 1;
     }
 
     if (sciErr.iErr)
     {
+        FREE(piOut);
         printError(&sciErr, 0);
         return 1;
     }
@@ -404,6 +408,23 @@ static int serialize_sparse(void *_pvCtx, int *_piAddr, int **_piBuffer, int *_p
 
     *_piBuffer = piOut;
     *_piBufferSize = iOutLen;
+
+    if (_bData)
+    {
+        if (iComplex)
+        {
+            freeAllocatedSparseMatrix(piRowCount, piColPos, pdblR);
+        }
+        else
+        {
+            freeAllocatedComplexSparseMatrix(piRowCount, piColPos, pdblR, pdblI);
+        }
+    }
+    else
+    {
+        freeAllocatedBooleanSparse(piRowCount, piColPos);
+    }
+
     return 0;
 }
 
index 3d5e7c1..d512409 100644 (file)
@@ -161,6 +161,7 @@ static int lengthStrings(int *piAddressVar)
     pStVarOne = (char**)MALLOC(sizeof(char*) * (m1 * n1));
     if (pStVarOne == NULL)
     {
+        FREE(lenStVarOne);
         Scierror(999, _("%s: No more memory.\n"), "length");
         return 0;
     }