Coverity: core module resource leaks fixed 91/18191/3
Dhruv Khattar [Sat, 28 May 2016 10:16:15 +0000 (15:16 +0530)]
Change-Id: If2dc6c234d420e03ab49254eac1f202b816b5496

scilab/modules/core/sci_gateway/c/sci_getdebuginfo.c
scilab/modules/core/sci_gateway/cpp/sci_getmd5.cpp
scilab/modules/core/sci_gateway/cpp/sci_getos.cpp
scilab/modules/core/sci_gateway/cpp/sci_sciargs.cpp
scilab/modules/core/src/c/getdynamicdebuginfo.c
scilab/modules/core/src/c/getmodules.c
scilab/modules/core/src/c/loadversion.c
scilab/modules/core/src/c/suspendProcess.c
scilab/modules/core/src/cpp/InitScilab.cpp
scilab/modules/core/src/cpp/tasks.cpp

index b384c65..82c979c 100644 (file)
@@ -50,6 +50,8 @@ int sci_getdebuginfo(char *fname, void* pvApiCtx)
     if (sciErr.iErr)
     {
         printError(&sciErr, 0);
+        freeArrayOfString(outputDynamicList, m1);
+        freeArrayOfString(outputStaticList, m2);
         return 0;
     }
 
@@ -61,6 +63,8 @@ int sci_getdebuginfo(char *fname, void* pvApiCtx)
         if (sciErr.iErr)
         {
             printError(&sciErr, 0);
+            freeArrayOfString(outputDynamicList, m1);
+            freeArrayOfString(outputStaticList, m2);
             return 0;
         }
 
index b3ee042..f1261d4 100644 (file)
@@ -82,7 +82,10 @@ types::Function::ReturnValue sci_getmd5(types::typed_list &in, int _iRetCount, t
         if (bStringMode)
         {
             pstPath = wide_string_to_UTF8(wcsCurrentIn);
-            pstMD5 = to_wide_string(md5_str(pstPath));
+            char* pstMD5_ = md5_str(pstPath);
+            pstMD5 = to_wide_string(pstMD5_);
+            FREE(pstPath);
+            FREE(pstMD5_);
         }
         else
         {
index 33c6773..68f6c5c 100644 (file)
@@ -34,12 +34,16 @@ types::Function::ReturnValue sci_getos(types::typed_list &in, int _iRetCount, ty
     if (in.size() != 0)
     {
         Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "getos", 0);
+        FREE(OperatingSystem);
+        OperatingSystem = NULL;
         return types::Function::Error;
     }
 
     if (_iRetCount != 2 && _iRetCount != 1 && _iRetCount != -1)
     {
         Scierror(78, _("%s: Wrong number of output argument(s): %d to %d expected.\n"), "getos", 1, 2);
+        FREE(OperatingSystem);
+        OperatingSystem = NULL;
         return types::Function::Error;
     }
 
index fdd2de2..57b652d 100644 (file)
@@ -42,6 +42,7 @@ types::Function::ReturnValue sci_sciargs(types::typed_list &in, int _iRetCount,
     {
         // call_scilab
         out.push_back(new types::String(L""));
+        freeArrayOfWideString(pwstCmdLineArgs, iCount);
         return types::Function::OK;
     }
 
index bd39771..db74f77 100644 (file)
@@ -402,7 +402,7 @@ char **getDynamicDebugInfo(int *sizeArray, int* pvApiCtx)
 
 #endif
 
-
+    FREE(value);
     sciErr = getNamedVarType(pvApiCtx, "SCI", &iType);
     if ((sciErr.iErr == 0) && (iType == 10))
     {
index 1c807cb..3cb13fd 100644 (file)
@@ -197,6 +197,10 @@ static BOOL AppendModules(char *xmlfilename)
                         {
                             /* we found the tag name */
                             const char *str = (const char*)attrib->children->content;
+                            if (name)
+                            {
+                                FREE(name);
+                            }
                             name = os_strdup(str);
                         }
                         else if (xmlStrEqual (attrib->name, (const xmlChar*) "activate"))
index 8c88a79..ed0d3d0 100644 (file)
@@ -51,6 +51,7 @@ BOOL getversionmodule(wchar_t* _pwstModule,
         len = (int)strlen(FORMATVERSIONFILENAME) + (int)strlen(SciPath) + (int)strlen(pstModule) + 1;
         filename_VERSION_module = (char*)MALLOC(sizeof(char) * len);
         sprintf(filename_VERSION_module, FORMATVERSIONFILENAME, SciPath, pstModule);
+        FREE(pstModule);
         if (SciPath)
         {
             FREE(SciPath);
@@ -91,6 +92,8 @@ BOOL getversionmodule(wchar_t* _pwstModule,
                 if (doc == NULL)
                 {
                     fprintf(stderr, _("Error: Could not parse file %s\n"), filename_VERSION_module);
+                    FREE(encoding);
+                    encoding = NULL;
                     return FALSE;
                 }
 
@@ -131,6 +134,10 @@ BOOL getversionmodule(wchar_t* _pwstModule,
                         {
                             /* we found <string> */
                             const char *str = (const char*)attrib->children->content;
+                            if (pwstSciVersionString)
+                            {
+                                FREE(pwstSciVersionString);
+                            }
                             pwstSciVersionString = to_wide_string(str);
                         }
 
@@ -151,6 +158,8 @@ BOOL getversionmodule(wchar_t* _pwstModule,
                 else
                 {
                     fprintf(stderr, _("Error: Not a valid version file %s (should start with <MODULE_VERSION> and contain <VERSION major='' minor='' maintenance='' revision='' string=''>)\n"), filename_VERSION_module);
+                    FREE(encoding);
+                    encoding = NULL;
                     return FALSE;
                 }
                 if (xpathObj)
index e50e4ee..9b7bfb7 100644 (file)
@@ -23,6 +23,7 @@
 #include "HistoryManager.h"
 #include "initConsoleMode.h"
 #include "suspendProcess.h"
+#include "sci_malloc.h"
 
 /*
  * Function called by signal when signum is caught.
@@ -89,6 +90,7 @@ void continueProcess(int signum)
         {
             printf("%s", currentLine);
             fflush(stdout);
+            FREE(currentLine);
         }
     }
 }
index 8266138..a6868c0 100644 (file)
@@ -613,6 +613,11 @@ void* scilabReadAndExecCommand(void* param)
     }
     while (ConfigVariable::getForceQuit() == false);
 
+    if(command)
+    {
+        FREE(command);
+    }
+
     return NULL;
 }
 
@@ -751,6 +756,7 @@ void* scilabReadAndStore(void* param)
                     {
                         sciprint(_("Debugger is on a breakpoint\n"));
                         sciprint(_("(c)ontinue or (a)bort current execution before execute a new command\n"));
+                        FREE(tmpCommand);
                         continue;
                     }
                 }
@@ -985,7 +991,9 @@ static int batchMain(ScilabEngineInfo* _pSEI)
 #ifdef DEBUG
     std::cerr << "To end program press [ENTER]" << std::endl;
 #endif
-    return parser->getExitStatus();
+    int ret = parser->getExitStatus();
+    delete parser;
+    return ret;
 }
 
 /*
index 50deded..0f24ac9 100644 (file)
@@ -123,7 +123,7 @@ void printAstTask(ast::Exp *tree, bool timed)
 
     if (tree)
     {
-        ast::PrintVisitor printMe = *new ast::PrintVisitor(std::wcout);
+        ast::PrintVisitor printMe (std::wcout);
         tree->accept(printMe);
     }
 
@@ -176,13 +176,11 @@ void execAstTask(ast::Exp* tree, bool serialize, bool timed, bool ASTtimed, bool
     {
         exec = new ast::TimedVisitor();
     }
-
-    if (execVerbose)
+    else if (execVerbose)
     {
         exec = new ast::StepVisitor();
     }
-
-    if (!execVerbose && !ASTtimed)
+    else
     {
         //call analyzer visitor before exec visitor
         if (ConfigVariable::getAnalyzerOptions() == 1)