Coverity: Ouput_stream module memory errors fixed 07/18307/3
Dhruv Khattar [Sat, 25 Jun 2016 22:03:22 +0000 (03:03 +0530)]
Change-Id: Id0cdce6b34ee0ef228ad648b54246233f2fd6f7f

scilab/modules/output_stream/sci_gateway/cpp/sci_diary.cpp
scilab/modules/output_stream/src/cpp/scilab_sprintf.cpp

index e36f3a7..3f26499 100644 (file)
@@ -297,12 +297,9 @@ static int sci_diary_one_rhs(char *fname, void* pvApiCtx)
             {
                 if (diaryClose(wcFilenames[0]))
                 {
-                    if (wcFilenames)
-                    {
-                        Scierror(999, _("%s: error can not close diary.\n"), fname);
-                        freeArrayOfWideString(wcFilenames, sizewcFilenames);
-                        return 0;
-                    }
+                    Scierror(999, _("%s: error can not close diary.\n"), fname);
+                    freeArrayOfWideString(wcFilenames, sizewcFilenames);
+                    return 0;
                 }
                 LhsVar(1) = 0;
             }
@@ -813,6 +810,7 @@ static wchar_t **getInputArgumentOneFilenames(char *fname, void* pvApiCtx, int *
                 {
                     Scierror(999, _("%s: Memory allocation error.\n"), fname);
                     *ierror = 1;
+                    FREE(lenStVarOne);
                 }
                 else
                 {
@@ -828,6 +826,8 @@ static wchar_t **getInputArgumentOneFilenames(char *fname, void* pvApiCtx, int *
                                 FREE(wcFilenames[i]);
                             }
                             FREE(wcFilenames);
+                            FREE(lenStVarOne);
+                            return NULL;
                         }
                     }
 
index 6675c36..a2c35d2 100644 (file)
@@ -772,7 +772,7 @@ static wchar_t* replaceAndCountLines(const wchar_t* _pwstInput, int* _piLines, i
 
     // do not count '\n' if it's at the end of string
     // it will be manage by piNewLine
-    if (pwstFirstOutput[iPos - 1] == '\n')
+    if (iPos > 0 && pwstFirstOutput[iPos - 1] == '\n')
     {
         (*_piLines)--;
         (*_piNewLine) = 1;