[gimp] Issue #2087 - Issues discovered by coverity scan



commit 2987f012f9289b7d608adbccc73166800b3dcf6a
Author: Josef Ridky <jridky redhat com>
Date:   Thu Aug 23 10:05:34 2018 +0200

    Issue #2087 - Issues discovered by coverity scan
    
    Add missing fclose invocations and fix copy-paste issue.
    
    This issues has been discovered by coverity scan proceeded by Red Hat.
    
    Fixed some mistakes in the patch and added more fclose() (Mitch)
    
    (cherry picked from commit 56c8f8320d7e738f8fbaaafce9863e38ac2bb373)

 plug-ins/common/file-cel.c             |  9 ++++++++
 plug-ins/common/file-gif-load.c        | 12 +++++++++++
 plug-ins/common/file-xbm.c             |  6 ++++++
 plug-ins/common/file-xmc.c             | 38 ++++++++++++++++++++++++++++------
 plug-ins/file-fli/fli-gimp.c           | 11 ++++++++--
 plug-ins/pygimp/plug-ins/whirlpinch.py |  2 +-
 6 files changed, 69 insertions(+), 9 deletions(-)
---
diff --git a/plug-ins/common/file-cel.c b/plug-ins/common/file-cel.c
index 0f929b0b40..feaf8a4bc3 100644
--- a/plug-ins/common/file-cel.c
+++ b/plug-ins/common/file-cel.c
@@ -361,6 +361,7 @@ load_image (const gchar  *file,
     {
       g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                    _("EOF or error while reading image header"));
+      fclose (fp);
       return -1;
     }
 
@@ -381,6 +382,7 @@ load_image (const gchar  *file,
         {
           g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                        _("EOF or error while reading image header"));
+          fclose (fp);
           return -1;
         }
 
@@ -389,6 +391,7 @@ load_image (const gchar  *file,
         {
           g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                        _("is not a CEL image file"));
+          fclose (fp);
           return -1;
         }
 
@@ -403,6 +406,7 @@ load_image (const gchar  *file,
         default:
           g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                        _("illegal bpp value in image: %hhu"), bpp);
+          fclose (fp);
           return -1;
         }
 
@@ -419,6 +423,7 @@ load_image (const gchar  *file,
                    _("illegal image dimensions: width: %d, horizontal offset: "
                      "%d, height: %d, vertical offset: %d"),
                    width, offx, height, offy);
+      fclose (fp);
       return -1;
     }
 
@@ -469,6 +474,7 @@ load_image (const gchar  *file,
             {
               g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                            _("EOF or error while reading image data"));
+              fclose (fp);
               return -1;
             }
 
@@ -505,6 +511,7 @@ load_image (const gchar  *file,
             {
               g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                            _("EOF or error while reading image data"));
+              fclose (fp);
               return -1;
             }
 
@@ -530,6 +537,7 @@ load_image (const gchar  *file,
             {
               g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                            _("EOF or error while reading image data"));
+              fclose (fp);
               return -1;
             }
 
@@ -547,6 +555,7 @@ load_image (const gchar  *file,
         default:
           g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                        _("Unsupported bit depth (%d)!"), bpp);
+          fclose (fp);
           return -1;
         }
 
diff --git a/plug-ins/common/file-gif-load.c b/plug-ins/common/file-gif-load.c
index 34716ce7d0..e4702f410a 100644
--- a/plug-ins/common/file-gif-load.c
+++ b/plug-ins/common/file-gif-load.c
@@ -366,6 +366,7 @@ load_image (const gchar  *filename,
   if (! ReadOK (fd, buf, 6))
     {
       g_message ("Error reading magic number");
+      fclose (fd);
       return -1;
     }
 
@@ -373,6 +374,7 @@ load_image (const gchar  *filename,
     {
       g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                    "%s", _("This is not a GIF file"));
+      fclose (fd);
       return -1;
     }
 
@@ -382,12 +384,14 @@ load_image (const gchar  *filename,
   if ((strcmp (version, "87a") != 0) && (strcmp (version, "89a") != 0))
     {
       g_message ("Bad version number, not '87a' or '89a'");
+      fclose (fd);
       return -1;
     }
 
   if (! ReadOK (fd, buf, 7))
     {
       g_message ("Failed to read screen descriptor");
+      fclose (fd);
       return -1;
     }
 
@@ -405,6 +409,7 @@ load_image (const gchar  *filename,
                           &GifScreen.GrayScale))
         {
           g_message ("Error reading global colormap");
+          fclose (fd);
           return -1;
         }
     }
@@ -422,12 +427,14 @@ load_image (const gchar  *filename,
       if (! ReadOK (fd, &c, 1))
         {
           g_message ("EOF / read error on image data");
+          fclose (fd);
           return image_ID; /* will be -1 if failed on first image! */
         }
 
       if (c == ';')
         {
           /* GIF terminator */
+          fclose (fd);
           return image_ID;
         }
 
@@ -437,6 +444,7 @@ load_image (const gchar  *filename,
           if (! ReadOK (fd, &c, 1))
             {
               g_message ("EOF / read error on extension function code");
+              fclose (fd);
               return image_ID; /* will be -1 if failed on first image! */
             }
 
@@ -456,6 +464,7 @@ load_image (const gchar  *filename,
       if (! ReadOK (fd, buf, 9))
         {
           g_message ("Couldn't read left/top/width/height");
+          fclose (fd);
           return image_ID; /* will be -1 if failed on first image! */
         }
 
@@ -468,6 +477,7 @@ load_image (const gchar  *filename,
           if (! ReadColorMap (fd, bitPixel, localColorMap, &grayScale))
             {
               g_message ("Error reading local colormap");
+              fclose (fd);
               return image_ID; /* will be -1 if failed on first image! */
             }
 
@@ -515,6 +525,8 @@ load_image (const gchar  *filename,
         break;
     }
 
+  fclose (fd);
+
   return image_ID;
 }
 
diff --git a/plug-ins/common/file-xbm.c b/plug-ins/common/file-xbm.c
index 649d9ed058..c2a1d5df15 100644
--- a/plug-ins/common/file-xbm.c
+++ b/plug-ins/common/file-xbm.c
@@ -826,6 +826,7 @@ load_image (const gchar  *filename,
     {
       g_message (_("'%s':\nCould not read header (ftell == %ld)"),
                  gimp_filename_to_utf8 (filename), ftell (fp));
+      fclose (fp);
       return -1;
     }
 
@@ -833,6 +834,7 @@ load_image (const gchar  *filename,
     {
       g_message (_("'%s':\nNo image width specified"),
                  gimp_filename_to_utf8 (filename));
+      fclose (fp);
       return -1;
     }
 
@@ -840,6 +842,7 @@ load_image (const gchar  *filename,
     {
       g_message (_("'%s':\nImage width is larger than GIMP can handle"),
                  gimp_filename_to_utf8 (filename));
+      fclose (fp);
       return -1;
     }
 
@@ -847,6 +850,7 @@ load_image (const gchar  *filename,
     {
       g_message (_("'%s':\nNo image height specified"),
                  gimp_filename_to_utf8 (filename));
+      fclose (fp);
       return -1;
     }
 
@@ -854,6 +858,7 @@ load_image (const gchar  *filename,
     {
       g_message (_("'%s':\nImage height is larger than GIMP can handle"),
                  gimp_filename_to_utf8 (filename));
+      fclose (fp);
       return -1;
     }
 
@@ -861,6 +866,7 @@ load_image (const gchar  *filename,
     {
       g_message (_("'%s':\nNo image data type specified"),
                  gimp_filename_to_utf8 (filename));
+      fclose (fp);
       return -1;
     }
 
diff --git a/plug-ins/common/file-xmc.c b/plug-ins/common/file-xmc.c
index cb878e90e2..be324385f5 100644
--- a/plug-ins/common/file-xmc.c
+++ b/plug-ins/common/file-xmc.c
@@ -667,10 +667,11 @@ load_image (const gchar  *filename,
       return -1;
     }
 
-  if (!XcursorFileLoad (fp, &commentsp, &imagesp))
+  if (! XcursorFileLoad (fp, &commentsp, &imagesp))
     {
       g_set_error (error, 0, 0, _("'%s' is not a valid X cursor."),
                    gimp_filename_to_utf8 (filename));
+      fclose (fp);
       return -1;
     }
 
@@ -683,6 +684,7 @@ load_image (const gchar  *filename,
           g_set_error (error, 0, 0,
                        _("Frame %d of '%s' is too wide for an X cursor."),
                        i + 1, gimp_filename_to_utf8 (filename));
+          fclose (fp);
           return -1;
         }
       if (imagesp->images[i]->height > MAX_LOAD_DIMENSION)
@@ -690,6 +692,7 @@ load_image (const gchar  *filename,
           g_set_error (error, 0, 0,
                        _("Frame %d of '%s' is too high for an X cursor."),
                        i + 1, gimp_filename_to_utf8 (filename));
+          fclose (fp);
           return -1;
         }
     }
@@ -706,7 +709,10 @@ load_image (const gchar  *filename,
   gimp_image_set_filename (image_ID, filename);
 
   if (! set_hotspot_to_parasite (image_ID))
-    return -1;
+    {
+      fclose (fp);
+      return -1;
+    }
 
   /* Temporary buffer */
   tmppixel = g_new (guint32, img_width * img_height);
@@ -729,8 +735,11 @@ load_image (const gchar  *filename,
 
       framename = make_framename (imagesp->images[i]->size, delay,
                                   DISPLAY_DIGIT (imagesp->nimage), error);
-      if (!framename)
-        return -1;
+      if (! framename)
+        {
+          fclose (fp);
+          return -1;
+        }
 
       layer_ID = gimp_layer_new (image_ID, framename, width, height,
                                  GIMP_RGBA_IMAGE,
@@ -782,6 +791,7 @@ load_image (const gchar  *filename,
                                       parasiteName[commentsp->comments[i]->comment_type -1]))
             {
               DM_XMC ("Failed to write %ith comment.\n", i);
+              fclose (fp);
               return -1;
             }
         }
@@ -868,6 +878,7 @@ load_thumbnail (const gchar *filename,
       g_set_error (error, 0, 0,
                    "'%s' seems to have an incorrect toc size.",
                    gimp_filename_to_utf8 (filename));
+      fclose (fp);
       return -1;
     }
   positions = g_malloc (ntoc * sizeof (guint32));
@@ -906,6 +917,7 @@ load_thumbnail (const gchar *filename,
       g_set_error (error, 0, 0,
                    _("there is no image chunk in \"%s\"."),
                    gimp_filename_to_utf8 (filename));
+      fclose (fp);
       return -1;
     }
 
@@ -946,6 +958,7 @@ load_thumbnail (const gchar *filename,
       g_set_error (error, 0, 0,
                    _("'%s' is too wide for an X cursor."),
                    gimp_filename_to_utf8 (filename));
+      fclose (fp);
       return -1;
     }
 
@@ -954,6 +967,7 @@ load_thumbnail (const gchar *filename,
       g_set_error (error, 0, 0,
                    _("'%s' is too high for an X cursor."),
                    gimp_filename_to_utf8 (filename));
+      fclose (fp);
       return -1;
     }
 
@@ -1497,6 +1511,7 @@ save_image (const gchar *filename,
   if (!imagesp)
     {
       DM_XMC ("Failed to XcursorImagesCreate!\n");
+      fclose (fp);
       return FALSE;
     }
   imagesp->nimage = nlayers;
@@ -1541,6 +1556,7 @@ save_image (const gchar *filename,
                        _("Frame '%s' is too wide. Please reduce to no more than %dpx."),
                        gimp_any_to_utf8 (framename, -1, NULL),
                        MAX_SAVE_DIMENSION);
+          fclose (fp);
           return FALSE;
         }
 
@@ -1550,6 +1566,7 @@ save_image (const gchar *filename,
                        _("Frame '%s' is too high. Please reduce to no more than %dpx."),
                        gimp_any_to_utf8 (framename, -1, NULL),
                        MAX_SAVE_DIMENSION);
+          fclose (fp);
           return FALSE;
         }
 
@@ -1558,6 +1575,7 @@ save_image (const gchar *filename,
           g_set_error (error, 0, 0,
                        _("Width and/or height of frame '%s' is zero!"),
                        gimp_any_to_utf8 (framename, -1, NULL));
+          fclose (fp);
           return FALSE;
         }
 
@@ -1578,6 +1596,7 @@ save_image (const gchar *filename,
               if (!imagesp->images[i])
                 {
                   DM_XMC ("Failed to XcursorImageCreate.\n");
+                  fclose (fp);
                   return FALSE;
                 }
               imagesp->images[i]->pixels[0] = 0x0;
@@ -1600,6 +1619,7 @@ save_image (const gchar *filename,
                              "Try to change the hot spot position, "
                              "layer geometry or export without auto-crop."),
                            gimp_any_to_utf8 (framename, -1, NULL));
+              fclose (fp);
               return FALSE;
             }
         }
@@ -1633,6 +1653,7 @@ save_image (const gchar *filename,
       if (!imagesp->images[i])
         {
           DM_XMC ("Failed to XcursorImageCreate.\n");
+          fclose (fp);
           return FALSE;
         }
       /*
@@ -1682,8 +1703,11 @@ save_image (const gchar *filename,
                                   imagesp->images[i]->delay,
                                   DISPLAY_DIGIT (imagesp->nimage),
                                   error);
-      if (!framename)
-        return FALSE;
+      if (! framename)
+        {
+          fclose (fp);
+          return FALSE;
+        }
 
       gimp_item_set_name (orig_layers[nlayers - 1 - i], framename);
       g_free (framename);
@@ -1742,6 +1766,7 @@ save_image (const gchar *filename,
         {
           DM_XMC ("Failed to XcursorFileSave.\t%p\t%p\t%p\n",
                   fp, commentsp, imagesp);
+          fclose (fp);
           return FALSE;
         }
 
@@ -1751,6 +1776,7 @@ save_image (const gchar *filename,
       if (! XcursorFileSaveImages (fp, imagesp))
         {
           DM_XMC ("Failed to XcursorFileSaveImages.\t%p\t%p\n", fp, imagesp);
+          fclose (fp);
           return FALSE;
         }
     }
diff --git a/plug-ins/file-fli/fli-gimp.c b/plug-ins/file-fli/fli-gimp.c
index e69b10f74a..d0753dd829 100644
--- a/plug-ins/file-fli/fli-gimp.c
+++ b/plug-ins/file-fli/fli-gimp.c
@@ -505,9 +505,14 @@ load_image (const gchar  *filename,
 
   fli_read_header (file, &fli_header);
   if (fli_header.magic == NO_HEADER)
-    return -1;
+    {
+      fclose (file);
+      return -1;
+    }
   else
-    fseek (file, 128, SEEK_SET);
+    {
+      fseek (file, 128, SEEK_SET);
+    }
 
   /*
    * Fix parameters
@@ -528,11 +533,13 @@ load_image (const gchar  *filename,
   if (to_frame < 1)
     {
       /* nothing to do ... */
+      fclose (file);
       return -1;
     }
   if (from_frame >= fli_header.frames)
     {
       /* nothing to do ... */
+      fclose (file);
       return -1;
     }
   if (to_frame>fli_header.frames)
diff --git a/plug-ins/pygimp/plug-ins/whirlpinch.py b/plug-ins/pygimp/plug-ins/whirlpinch.py
index a874ff1e75..3b166dece1 100755
--- a/plug-ins/pygimp/plug-ins/whirlpinch.py
+++ b/plug-ins/pygimp/plug-ins/whirlpinch.py
@@ -125,7 +125,7 @@ def whirl_pinch(image, drawable, whirl, pinch, radius):
                                 if cx >= 0: ix = int(cx)
                                 else:       ix = -(int(-cx) + 1)
                                 if cy >= 0: iy = int(cy)
-                                else:       iy = -(int(-cx) + 1)
+                                else:       iy = -(int(-cy) + 1)
                                 pixel[0] = pft.get_pixel(ix, iy)
                                 pixel[1] = pft.get_pixel(ix+1, iy)
                                 pixel[2] = pft.get_pixel(ix, iy+1)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]