Coverity: graphic_export module resource leaks fixed 37/18237/2
Dhruv Khattar [Sun, 12 Jun 2016 18:09:06 +0000 (23:09 +0530)]
Change-Id: Iaed5322d5010e093c90677559258e9d2aba564e3

scilab/modules/graphic_export/sci_gateway/cpp/sci_xend.cpp
scilab/modules/graphic_export/sci_gateway/cpp/sci_xinit.cpp
scilab/modules/graphic_export/src/cpp/xs2file.cpp

index 169b0f4..072c474 100644 (file)
@@ -51,6 +51,7 @@ int sci_xend(char * fname, void *pvApiCtx)
                 Scierror(999, _("%s: An error occurred: %s\n"), fname, ret);
                 return 0;
             }
+            delete[] ret;
         }
     }
 
index f613bc8..8f0b85d 100644 (file)
@@ -68,6 +68,7 @@ int sci_xinit(char * fname, void *pvApiCtx)
     else
     {
         Scierror(999, _("%s: Invalid path: %s.\n"), fname, path);
+        freeAllocatedSingleString(path);
         return 0;
     }
 
index 05adfd4..dcfb48d 100644 (file)
@@ -188,8 +188,8 @@ int xs2file(char * fname, ExportFileType fileType, void* pvApiCtx)
 
                     if ((!checkInputArgumentType(pvApiCtx, 3, sci_strings)))
                     {
-                        freeAllocatedMatrixOfString(m1, n1, fileName);
                         Scierror(999, _("%s: Wrong type for input argument #%d: Single character string expected.\n"), fname, 3);
+                        freeAllocatedMatrixOfString(m1, n1, fileName);
                         return 1;
                     }
 
@@ -197,14 +197,15 @@ int xs2file(char * fname, ExportFileType fileType, void* pvApiCtx)
                     if (sciErr.iErr)
                     {
                         printError(&sciErr, 0);
+                        freeAllocatedMatrixOfString(m1, n1, fileName);
                         return 1;
                     }
 
                     // Retrieve a matrix of string at position 3.
                     if (getAllocatedMatrixOfString(pvApiCtx, piAddrsciOrientation, &nbRow, &nbCol, &sciOrientation))
                     {
-                        freeAllocatedMatrixOfString(m1, n1, fileName);
                         Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 3);
+                        freeAllocatedMatrixOfString(m1, n1, fileName);
                         return 1;
                     }
 
@@ -224,17 +225,17 @@ int xs2file(char * fname, ExportFileType fileType, void* pvApiCtx)
                         }
                         else
                         {
+                            Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 3, "portrait", "landscape");
                             freeAllocatedMatrixOfString(m1, n1, fileName);
                             freeAllocatedMatrixOfString(nbRow, nbCol, sciOrientation);
-                            Scierror(999, _("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), fname, 3, "portrait", "landscape");
                             return 1;
                         }
                     }
                     else
                     {
+                        Scierror(999, _("%s: Wrong size for input argument #%d: Single character string expected.\n"), fname, 3);
                         freeAllocatedMatrixOfString(m1, n1, fileName);
                         freeAllocatedMatrixOfString(nbRow, nbCol, sciOrientation);
-                        Scierror(999, _("%s: Wrong size for input argument #%d: Single character string expected.\n"), fname, 3);
                         return 1;
                     }
                 }
@@ -244,6 +245,7 @@ int xs2file(char * fname, ExportFileType fileType, void* pvApiCtx)
                     if (sciErr.iErr)
                     {
                         printError(&sciErr, 0);
+                        freeAllocatedMatrixOfString(m1, n1, fileName);
                         return 1;
                     }
 
@@ -251,16 +253,16 @@ int xs2file(char * fname, ExportFileType fileType, void* pvApiCtx)
                     sciErr = getMatrixOfDouble(pvApiCtx, piAddrquality, &nbRow, &nbCol, &quality);
                     if (sciErr.iErr)
                     {
-                        freeAllocatedMatrixOfString(m1, n1, fileName);
                         printError(&sciErr, 0);
                         Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), fname, 3);
+                        freeAllocatedMatrixOfString(m1, n1, fileName);
                         return 1;
                     }
 
                     if (nbRow != 1 || nbCol != 1 || *quality < 0 || *quality > 1)
                     {
-                        freeAllocatedMatrixOfString(m1, n1, fileName);
                         Scierror(999, _("%s: Wrong type for input argument #%d: A real between 0 and 1 expected.\n"), fname, 3);
+                        freeAllocatedMatrixOfString(m1, n1, fileName);
                         return 1;
                     }
                     jpegCompressionQuality = (float) * quality;
@@ -269,6 +271,7 @@ int xs2file(char * fname, ExportFileType fileType, void* pvApiCtx)
 
             /* Replaces SCI, ~, HOME, TMPDIR by the real path */
             real_filename = expandPathVariable(fileName[0]);
+            freeAllocatedMatrixOfString(m1, n1, fileName);
 
             /* Call the function for exporting file */
             status = exportToFile(figureUID, real_filename, fileType, jpegCompressionQuality, orientation);
@@ -279,7 +282,6 @@ int xs2file(char * fname, ExportFileType fileType, void* pvApiCtx)
                 FREE(real_filename);
                 real_filename = NULL;
             }
-            freeAllocatedMatrixOfString(m1, n1, fileName);
 
             /* treat errors */
             if (strlen(status) != 0)
@@ -293,8 +295,8 @@ int xs2file(char * fname, ExportFileType fileType, void* pvApiCtx)
         }
         else
         {
-            freeAllocatedMatrixOfString(m1, n1, fileName);
             Scierror(999, _("%s: Wrong size for input argument #%d: Single character string expected.\n"), fname, 2);
+            freeAllocatedMatrixOfString(m1, n1, fileName);
             return 1;
         }
     }