Coverity: io module resource leaks fixed 67/18167/3
Dhruv Khattar [Sun, 15 May 2016 07:08:42 +0000 (12:08 +0530)]
Change-Id: Ibd42b79b71e7b680aa3d2b60c31c7dc65eaf0c9c

scilab/modules/io/sci_gateway/cpp/sci_genlib.cpp
scilab/modules/io/sci_gateway/cpp/sci_read.cpp
scilab/modules/io/sci_gateway/cpp/sci_write.cpp
scilab/modules/io/src/cpp/loadlib.cpp

index f962fce..9841409 100644 (file)
@@ -239,6 +239,8 @@ types::Function::ReturnValue sci_genlib(types::typed_list &in, int _iRetCount, t
                 char* pstr = wide_string_to_UTF8(stFullPath.data());
                 Scierror(999, _("%s: Cannot open file ''%s''.\n"), "genlib", pstr);
                 FREE(pstr);
+                FREE(pstParsePath);
+                freeArrayOfWideString(pstPath, iNbFile);
                 pLib->killMe();
                 return types::Function::Error;
             }
@@ -462,6 +464,8 @@ xmlTextWriterPtr openXMLFile(const wchar_t *_pstFilename, const wchar_t* _pstLib
     pWriter = xmlNewTextWriterFilename(pstFilename, 0);
     if (pWriter == NULL)
     {
+        FREE(pstFilename);
+        FREE(pstLibName);
         return NULL;
     }
 
@@ -474,6 +478,8 @@ xmlTextWriterPtr openXMLFile(const wchar_t *_pstFilename, const wchar_t* _pstLib
     if (iLen < 0)
     {
         closeXMLFile(pWriter);
+        FREE(pstFilename);
+        FREE(pstLibName);
         return NULL;
     }
 
@@ -482,6 +488,8 @@ xmlTextWriterPtr openXMLFile(const wchar_t *_pstFilename, const wchar_t* _pstLib
     if (iLen < 0)
     {
         closeXMLFile(pWriter);
+        FREE(pstFilename);
+        FREE(pstLibName);
         return NULL;
     }
 
@@ -490,6 +498,8 @@ xmlTextWriterPtr openXMLFile(const wchar_t *_pstFilename, const wchar_t* _pstLib
     if (iLen < 0)
     {
         closeXMLFile(pWriter);
+        FREE(pstFilename);
+        FREE(pstLibName);
         return NULL;
     }
 
index 40a0366..867e40b 100644 (file)
@@ -427,6 +427,7 @@ types::Function::ReturnValue sci_read(types::typed_list &in, int _iRetCount, typ
                             {
                                 pD->set((iRows - 1), i, pdData[i]);
                             }
+                            delete[] pdData;
                         }
 
                         //next line
index 8bb37f9..09b4b88 100644 (file)
@@ -152,8 +152,9 @@ types::Function::ReturnValue sci_write(types::typed_list &in, int _iRetCount, ty
         itTypeOfData = checkformat(pstFormat);
         if (itTypeOfData == types::InternalType::ScilabNull)
         {
-            closeFile(in[0], iID);
             Scierror(999, _("Incorrect file or format.\n"));
+            closeFile(in[0], iID);
+            FREE(pstFormat);
             return types::Function::Error;
         }
     }
@@ -309,6 +310,7 @@ types::Function::ReturnValue sci_write(types::typed_list &in, int _iRetCount, ty
                 {
                     Scierror(999, _("%s: Wrong type for input argument #%d : string expected.\n"), "write", 2);
                     closeFile(in[0], iID);
+                    FREE(pstFormat);
                     return types::Function::Error;
                 }
             }
@@ -423,17 +425,14 @@ types::Function::ReturnValue sci_write(types::typed_list &in, int _iRetCount, ty
                 default:
                 {
                     Scierror(999, _("%s: Wrong type for input argument #%d : string expected.\n"), "write", 2);
+                    FREE(pstFormat);
                     return types::Function::Error;
                 }
             }
         }
     }
 
-    if (pstFormat)
-    {
-        FREE(pstFormat);
-    }
-
+    FREE(pstFormat);
     if (error != 0)
     {
         Scierror(999, _("Incorrect file or format.\n"));
index 57cad00..497eb73 100644 (file)
@@ -129,6 +129,7 @@ int parseLibFile(const std::wstring& _wstXML, MacroInfoList& info, std::wstring&
         file.read(&*readXMLDecl.begin(),XMLDecl.length());
         if (XMLDecl != readXMLDecl)
         {
+          FREE(pstFile);
           return 4;
         }
     }