Coverity: tclsci module memory errors fixed 29/18229/2
Dhruv Khattar [Tue, 7 Jun 2016 20:45:20 +0000 (01:45 +0530)]
Change-Id: Icc2923fba963281cb4294a6bdc65a89f64a26c0a

scilab/modules/tclsci/sci_gateway/c/sci_TCL_GetVersion.c
scilab/modules/tclsci/sci_gateway/c/sci_TCL_SetVar.c
scilab/modules/tclsci/src/c/InitTclTk.c
scilab/modules/tclsci/src/c/TCL_Command.c
scilab/modules/tclsci/src/cpp/ScilabEval.cpp

index 947a28b..6912768 100644 (file)
@@ -115,11 +115,8 @@ int sci_TCL_GetVersion(char *fname, void* pvApiCtx)
                     return 1;
                 }
 
-                if (VERSIONMATRIX)
-                {
-                    FREE(VERSIONMATRIX);
-                    VERSIONMATRIX = NULL;
-                }
+                FREE(VERSIONMATRIX);
+                VERSIONMATRIX = NULL;
                 AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
                 ReturnArguments(pvApiCtx);
             }
index 4f67111..6a33a91 100644 (file)
@@ -113,6 +113,7 @@ int sci_TCL_SetVar(char *fname, void* pvApiCtx)
         if (sciErr.iErr)
         {
             printError(&sciErr, 0);
+            freeAllocatedSingleString(VarName);
             return 1;
         }
 
@@ -120,6 +121,7 @@ int sci_TCL_SetVar(char *fname, void* pvApiCtx)
         if (getAllocatedMatrixOfString(pvApiCtx, piAddrStr, &m1, &n1, &Str))
         {
             Scierror(202, _("%s: Wrong type for argument #%d: String matrix expected.\n"), fname, 2);
+            freeAllocatedSingleString(VarName);
             return 1;
         }
 
index dcd9d10..d088b93 100644 (file)
@@ -68,6 +68,7 @@ static void *DaemonOpenTCLsci(void* in)
     if (SciPath == NULL)
     {
         sciprint(_("The SCI environment variable is not set.\nTCL initialisation failed !\n"));
+        return (0);
     }
 
 
@@ -93,6 +94,7 @@ static void *DaemonOpenTCLsci(void* in)
     if (tmpfile2 == NULL)
     {
         sciprint(_("Unable to find Tcl initialisation scripts.\nCheck your SCI environment variable.\nTcl initialisation failed !"));
+        return (0);
     }
     else
     {
@@ -103,6 +105,7 @@ static void *DaemonOpenTCLsci(void* in)
     if (tmpdir == NULL)
     {
         sciprint(_("The SCI environment variable is not set.\nTcl initialisation failed !\n"));
+        return (0);
     }
     else
     {
@@ -115,6 +118,7 @@ static void *DaemonOpenTCLsci(void* in)
     if (tmpfile2 == NULL)
     {
         sciprint(_("Unable to find Tcl initialisation scripts.\nCheck your SCI environment variable.\nTcl initialisation failed !"));
+        return (0);
     }
     else
     {
@@ -136,6 +140,7 @@ static void *DaemonOpenTCLsci(void* in)
         if ( getTclInterp() == NULL )
         {
             Scierror(999, _("Tcl Error: Unable to create Tcl interpreter (Tcl_CreateInterp).\n"));
+            return (0);
         }
         releaseTclInterp();
 
@@ -143,6 +148,7 @@ static void *DaemonOpenTCLsci(void* in)
         {
             releaseTclInterp();
             Scierror(999, _("Tcl Error: Error during the Tcl initialization (Tcl_Init): %s\n"), Tcl_GetStringResult(getTclInterp()));
+            return (0);
         }
         releaseTclInterp();
         if (getenv("SCI_DISABLE_TK") == NULL)
@@ -169,6 +175,7 @@ static void *DaemonOpenTCLsci(void* in)
         {
             releaseTclInterp();
             Scierror(999, _("Tcl Error: Error during the Scilab/Tcl init process. Could not set SciPath: %s\n"), Tcl_GetStringResult(getTclInterp()));
+            return (0);
         }
 
         releaseTclInterp();
@@ -186,28 +193,20 @@ static void *DaemonOpenTCLsci(void* in)
         {
             releaseTclInterp();
             Scierror(999, _("Tcl Error: Error during the Scilab/TK init process. Error while loading %s: %s\n"), TkScriptpathShort, Tcl_GetStringResult(getTclInterp()));
+            return (0);
         }
         releaseTclInterp();
     }
 
 
-    if (SciPath)
-    {
-        FREE(SciPath);
-        SciPath = NULL;
-    }
+    FREE(SciPath);
+    SciPath = NULL;
 
-    if (SciPathShort)
-    {
-        FREE(SciPathShort);
-        SciPathShort = NULL;
-    }
+    FREE(SciPathShort);
+    SciPathShort = NULL;
 
-    if (TkScriptpathShort)
-    {
-        FREE(TkScriptpathShort);
-        TkScriptpathShort = NULL;
-    }
+    FREE(TkScriptpathShort);
+    TkScriptpathShort = NULL;
 
     // This start a periodic and endless call to "update"
     // TCL command. This causes any TCL application to start
index 0e62433..3bc3c55 100644 (file)
@@ -195,6 +195,10 @@ void startTclLoop()
             /* Update return value and result */
             if (Tcl_GetStringResult(LocalTCLinterp) && strlen(Tcl_GetStringResult(LocalTCLinterp)) != 0)
             {
+                if (TclInterpResult)
+                {
+                    FREE(TclInterpResult);
+                }
                 TclInterpResult = os_strdup(Tcl_GetStringResult(LocalTCLinterp));
             }
             else
index ebfc794..c903030 100644 (file)
@@ -54,6 +54,7 @@ int TCL_EvalScilabCmd(ClientData clientData, Tcl_Interp * theinterp, int objc, C
             pos = str.find('\n');
         }
 
+        FREE(pstCommand);
         pstCommand =  strdup(str.c_str());
 
         if (strncmp(pstCommand, "flush", 5) == 0)