Coverity #1098450, #1098809, #1098910, #1099327 fixed 68/18368/4
Dhruv Khattar [Sat, 16 Jul 2016 10:42:08 +0000 (15:42 +0530)]
Change-Id: I241c0eb4de6d8f6289f5ee37e68f6969d1d0bcee

scilab/modules/external_objects/src/cpp/ScilabObjects.cpp
scilab/modules/external_objects/src/cpp/import.cpp
scilab/modules/external_objects/src/cpp/invoke_asref.cpp
scilab/modules/external_objects/src/cpp/wrap.cpp

index f00f48e..a8849c7 100644 (file)
@@ -237,8 +237,8 @@ void ScilabObjects::removeVar(int * addr, void * pvApiCtx)
 
             env.removeobject(*id);
             deleteNamedVariable(pvApiCtx, varName);
-            freeAllocatedSingleString(varName);
         }
+        freeAllocatedSingleString(varName);
     }
 }
 
index 5109deb..1484b5f 100644 (file)
@@ -80,9 +80,9 @@ int ScilabGateway::import(char * fname, const int envId, void * pvApiCtx)
     else
     {
         className = (char**)MALLOC(sizeof(char *) * nbArgs);
-        for (int i = 1; i <= nbArgs; i++)
+        for (int i = 0; i < nbArgs; i++)
         {
-            err = getVarAddressFromPosition(pvApiCtx, i, &addr);
+            err = getVarAddressFromPosition(pvApiCtx, i + 1, &addr);
             if (err.iErr)
             {
                 freeAllocatedMatrixOfString(1, i, className);
@@ -92,10 +92,10 @@ int ScilabGateway::import(char * fname, const int envId, void * pvApiCtx)
             if (!isStringType(pvApiCtx, addr))
             {
                 freeAllocatedMatrixOfString(1, i, className);
-                throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: A String expected."), i);
+                throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Wrong type for input argument #%d: A String expected."), i + 1);
             }
 
-            if (getAllocatedSingleString(pvApiCtx, addr, &(className[i - 1])))
+            if (getAllocatedSingleString(pvApiCtx, addr, &(className[i])))
             {
                 freeAllocatedMatrixOfString(1, i, className);
                 throw ScilabAbstractEnvironmentException(__LINE__, __FILE__, gettext("Invalid variable: cannot retrieve the data"));
index 981cf10..5bacfa3 100644 (file)
@@ -74,7 +74,7 @@ int ScilabGateway::invoke_asref(char * fname, const int envId, void * pvApiCtx)
 
         try
         {
-            char * varName =  ScilabObjects::getSingleString(i + 3, pvApiCtx);
+            varName =  ScilabObjects::getSingleString(i + 3, pvApiCtx);
             err = getVarAddressFromName(pvApiCtx, varName, &addr);
             if (err.iErr)
             {
index cb409cb..bb07b23 100644 (file)
@@ -76,6 +76,7 @@ int ScilabGateway::wrap(char * fname, const int envId, void * pvApiCtx)
     }
 
     PutLhsVar();
+    delete[] tmpvar;
 
     return 0;
 }