[gimp/soc-2010-cage-2] Fix memory and descriptor leaks



commit cb76b748d5e9f149479d1574d783f4f5a83fd843
Author: Nelson A. de Oliveira <naoliv debian org>
Date:   Tue Nov 9 16:03:47 2010 -0200

    Fix memory and descriptor leaks

 modules/gimpinputdevicestore-dx.c                  |    7 ++++++-
 plug-ins/common/crop-zealous.c                     |    2 ++
 plug-ins/common/curve-bend.c                       |    1 +
 plug-ins/common/file-cel.c                         |    1 +
 plug-ins/common/file-compressor.c                  |    1 +
 plug-ins/common/file-csource.c                     |    1 +
 plug-ins/common/file-dicom.c                       |    4 ++++
 plug-ins/common/file-gbr.c                         |    1 +
 plug-ins/common/file-gih.c                         |    1 +
 plug-ins/common/file-header.c                      |    2 ++
 plug-ins/common/file-html-table.c                  |    1 +
 plug-ins/common/file-pcx.c                         |    8 ++++++++
 plug-ins/common/file-psp.c                         |    1 +
 plug-ins/common/file-sunras.c                      |    1 +
 plug-ins/common/file-xwd.c                         |    4 ++++
 plug-ins/common/mail.c                             |    2 ++
 plug-ins/file-bmp/bmp-read.c                       |    1 +
 plug-ins/file-ico/ico-save.c                       |    1 +
 plug-ins/file-psd/psd-image-res-load.c             |    7 +++++++
 plug-ins/file-psd/psd-load.c                       |    3 +++
 plug-ins/file-psd/psd-util.c                       |    2 ++
 .../fractal-explorer/fractal-explorer-dialogs.c    |    2 ++
 plug-ins/fractal-explorer/fractal-explorer.c       |    2 ++
 plug-ins/gfig/gfig.c                               |    4 ++++
 plug-ins/gimpressionist/ppmtool.c                  |    1 +
 plug-ins/ifs-compose/ifs-compose-utils.c           |    1 +
 26 files changed, 61 insertions(+), 1 deletions(-)
---
diff --git a/modules/gimpinputdevicestore-dx.c b/modules/gimpinputdevicestore-dx.c
index a428f99..2917f01 100644
--- a/modules/gimpinputdevicestore-dx.c
+++ b/modules/gimpinputdevicestore-dx.c
@@ -366,7 +366,10 @@ gimp_input_device_store_add (GimpInputDeviceStore *store,
                                                      guid,
                                                      &didevice8,
                                                      NULL))))
-    return FALSE;
+    {
+      g_free (guidstring);
+      return FALSE;
+    }
 
   if (FAILED ((hresult = IDirectInputDevice8_SetCooperativeLevel (didevice8,
                                                                   (HWND) gdk_win32_drawable_get_handle (store->window),
@@ -374,6 +377,7 @@ gimp_input_device_store_add (GimpInputDeviceStore *store,
     {
       g_warning ("IDirectInputDevice8::SetCooperativeLevel failed: %s",
                  g_win32_error_message (hresult));
+      g_free (guidstring);
       return FALSE;
     }
 
@@ -383,6 +387,7 @@ gimp_input_device_store_add (GimpInputDeviceStore *store,
     {
       g_warning ("IDirectInputDevice8::GetDeviceInfo failed: %s",
                  g_win32_error_message (hresult));
+      g_free (guidstring);
       return FALSE;
     }
 
diff --git a/plug-ins/common/crop-zealous.c b/plug-ins/common/crop-zealous.c
index 1960012..409603b 100644
--- a/plug-ins/common/crop-zealous.c
+++ b/plug-ins/common/crop-zealous.c
@@ -236,6 +236,8 @@ do_zcrop (GimpDrawable *drawable,
       (livingcols == width && livingrows == height))
     {
       g_message (_("Nothing to crop."));
+      g_free (killrows);
+      g_free (killcols);
       return;
     }
 
diff --git a/plug-ins/common/curve-bend.c b/plug-ins/common/curve-bend.c
index da67755..1abb235 100644
--- a/plug-ins/common/curve-bend.c
+++ b/plug-ins/common/curve-bend.c
@@ -900,6 +900,7 @@ p_load_pointfile (BenderDialog *cd,
     {
       g_message (_("Error while reading '%s': %s"),
                  gimp_filename_to_utf8 (filename), g_strerror (errno));
+      fclose (l_fp);
       return -1;
     }
 
diff --git a/plug-ins/common/file-cel.c b/plug-ins/common/file-cel.c
index 040a8c8..8118aab 100644
--- a/plug-ins/common/file-cel.c
+++ b/plug-ins/common/file-cel.c
@@ -351,6 +351,7 @@ load_image (const gchar  *file,
   if (image == -1)
     {
       g_message (_("Can't create a new image"));
+      fclose (fp);
       return -1;
     }
 
diff --git a/plug-ins/common/file-compressor.c b/plug-ins/common/file-compressor.c
index 72eee03..44d5ab2 100644
--- a/plug-ins/common/file-compressor.c
+++ b/plug-ins/common/file-compressor.c
@@ -601,6 +601,7 @@ load_image (const Compressor   *compressor,
 
         g_unlink (tmpname);
         g_free (tmpname);
+        fclose (f);
 
         *status = GIMP_PDB_EXECUTION_ERROR;
         return -1;
diff --git a/plug-ins/common/file-csource.c b/plug-ins/common/file-csource.c
index aade831..f3b18c8 100644
--- a/plug-ins/common/file-csource.c
+++ b/plug-ins/common/file-csource.c
@@ -654,6 +654,7 @@ save_image (Config  *config,
       break;
     default:
       g_warning ("unhandled drawable type (%d)", drawable_type);
+      fclose (fp);
       return FALSE;
     }
   if (!config->use_macros)
diff --git a/plug-ins/common/file-dicom.c b/plug-ins/common/file-dicom.c
index 92d9dd2..d4fbe8f 100644
--- a/plug-ins/common/file-dicom.c
+++ b/plug-ins/common/file-dicom.c
@@ -356,6 +356,8 @@ load_image (const gchar  *filename,
       g_message ("'%s' is a PAPYRUS DICOM file.\n"
                  "This plug-in does not support this type yet.",
                  gimp_filename_to_utf8 (filename));
+      g_free (dicominfo);
+      fclose (DICOM);
       return -1;
     }
 
@@ -365,6 +367,8 @@ load_image (const gchar  *filename,
       g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                    _("'%s' is not a DICOM file."),
                    gimp_filename_to_utf8 (filename));
+      g_free (dicominfo);
+      fclose (DICOM);
       return -1;
     }
 
diff --git a/plug-ins/common/file-gbr.c b/plug-ins/common/file-gbr.c
index e9ce57e..805b0b2 100644
--- a/plug-ins/common/file-gbr.c
+++ b/plug-ins/common/file-gbr.c
@@ -578,6 +578,7 @@ load_image (const gchar  *filename,
       g_message ("Unsupported brush depth: %d\n"
                  "GIMP Brushes must be GRAY or RGBA\n",
                  bh.bytes);
+      g_free (name);
       return -1;
     }
 
diff --git a/plug-ins/common/file-gih.c b/plug-ins/common/file-gih.c
index 4c6cbd6..d5eb257 100644
--- a/plug-ins/common/file-gih.c
+++ b/plug-ins/common/file-gih.c
@@ -575,6 +575,7 @@ gih_load_one_brush (gint   fd,
       g_message ("Unsupported brush depth: %d\n"
                  "GIMP Brushes must be GRAY or RGBA\n",
                  bh.bytes);
+      g_free (name);
       return FALSE;
     }
 
diff --git a/plug-ins/common/file-header.c b/plug-ins/common/file-header.c
index 583a123..983b526 100644
--- a/plug-ins/common/file-header.c
+++ b/plug-ins/common/file-header.c
@@ -290,6 +290,8 @@ save_image (const gchar *filename,
 
     default:
       g_warning ("unhandled drawable type (%d)", drawable_type);
+      fclose (fp);
+      g_free (data);
       return FALSE;
     }
 
diff --git a/plug-ins/common/file-html-table.c b/plug-ins/common/file-html-table.c
index dd7e03f..e60a02b 100644
--- a/plug-ins/common/file-html-table.c
+++ b/plug-ins/common/file-html-table.c
@@ -234,6 +234,7 @@ save_image (const gchar   *filename,
       g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
                    _("Could not open '%s' for writing: %s"),
                    gimp_filename_to_utf8 (filename), g_strerror (errno));
+      g_free (palloc);
       return FALSE;
     }
 
diff --git a/plug-ins/common/file-pcx.c b/plug-ins/common/file-pcx.c
index 51c6479..57cd29a 100644
--- a/plug-ins/common/file-pcx.c
+++ b/plug-ins/common/file-pcx.c
@@ -370,6 +370,7 @@ load_image (const gchar  *filename,
       g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                    _("Could not read header from '%s'"),
                    gimp_filename_to_utf8 (filename));
+      fclose (fd);
       return -1;
     }
 
@@ -380,6 +381,7 @@ load_image (const gchar  *filename,
       g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                    _("'%s' is not a PCX file"),
                    gimp_filename_to_utf8 (filename));
+      fclose (fd);
       return -1;
     }
 
@@ -392,16 +394,19 @@ load_image (const gchar  *filename,
   if ((width < 0) || (width > GIMP_MAX_IMAGE_SIZE))
     {
       g_message (_("Unsupported or invalid image width: %d"), width);
+      fclose (fd);
       return -1;
     }
   if ((height < 0) || (height > GIMP_MAX_IMAGE_SIZE))
     {
       g_message (_("Unsupported or invalid image height: %d"), height);
+      fclose (fd);
       return -1;
     }
   if (bytesperline < (width * pcx_header.bpp) / 8)
     {
       g_message (_("Invalid number of bytes per line in PCX header"));
+      fclose (fd);
       return -1;
     }
 
@@ -409,6 +414,7 @@ load_image (const gchar  *filename,
   if (G_MAXSIZE / width / height < 3)
     {
       g_message (_("Image dimensions too large: width %d x height %d"), width, height);
+      fclose (fd);
       return -1;
     }
 
@@ -457,12 +463,14 @@ load_image (const gchar  *filename,
   else
     {
       g_message (_("Unusual PCX flavour, giving up"));
+      fclose (fd);
       return -1;
     }
 
   gimp_pixel_rgn_init (&pixel_rgn, drawable, 0, 0, width, height, TRUE, FALSE);
   gimp_pixel_rgn_set_rect (&pixel_rgn, dest, 0, 0, width, height);
 
+  fclose (fd);
   g_free (dest);
 
   gimp_drawable_flush (drawable);
diff --git a/plug-ins/common/file-psp.c b/plug-ins/common/file-psp.c
index da53903..ef39d5b 100644
--- a/plug-ins/common/file-psp.c
+++ b/plug-ins/common/file-psp.c
@@ -886,6 +886,7 @@ read_creator_block (FILE     *f,
           if (fread (string, length, 1, f) < 1)
             {
               g_message ("Error reading creator keyword data");
+              g_free (string);
               return -1;
             }
           switch (keyword)
diff --git a/plug-ins/common/file-sunras.c b/plug-ins/common/file-sunras.c
index d0784a1..fce0164 100644
--- a/plug-ins/common/file-sunras.c
+++ b/plug-ins/common/file-sunras.c
@@ -440,6 +440,7 @@ load_image (const gchar  *filename,
           g_message (_("Could not read color entries from '%s'"),
                      gimp_filename_to_utf8 (filename));
           fclose (ifp);
+          g_free (suncolmap);
           return (-1);
         }
     }
diff --git a/plug-ins/common/file-xwd.c b/plug-ins/common/file-xwd.c
index dd758eb..00f5d98 100644
--- a/plug-ins/common/file-xwd.c
+++ b/plug-ins/common/file-xwd.c
@@ -487,6 +487,7 @@ load_image (const gchar  *filename,
     {
       g_message (_("'%s':\nNo image width specified"),
                  gimp_filename_to_utf8 (filename));
+      g_free (xwdcolmap);
       fclose (ifp);
       return (-1);
     }
@@ -496,6 +497,7 @@ load_image (const gchar  *filename,
     {
       g_message (_("'%s':\nImage width is larger than GIMP can handle"),
                  gimp_filename_to_utf8 (filename));
+      g_free (xwdcolmap);
       fclose (ifp);
       return (-1);
     }
@@ -504,6 +506,7 @@ load_image (const gchar  *filename,
     {
       g_message (_("'%s':\nNo image height specified"),
                  gimp_filename_to_utf8 (filename));
+      g_free (xwdcolmap);
       fclose (ifp);
       return (-1);
     }
@@ -512,6 +515,7 @@ load_image (const gchar  *filename,
     {
       g_message (_("'%s':\nImage height is larger than GIMP can handle"),
                  gimp_filename_to_utf8 (filename));
+      g_free (xwdcolmap);
       fclose (ifp);
       return (-1);
     }
diff --git a/plug-ins/common/mail.c b/plug-ins/common/mail.c
index 5e09eb7..61f3c4f 100644
--- a/plug-ins/common/mail.c
+++ b/plug-ins/common/mail.c
@@ -606,6 +606,8 @@ find_extension (const gchar *filename)
         }
     }
 
+  g_free (filename_copy);
+
   return ext;
 }
 
diff --git a/plug-ins/file-bmp/bmp-read.c b/plug-ins/file-bmp/bmp-read.c
index f72e6b7..59a1dfa 100644
--- a/plug-ins/file-bmp/bmp-read.c
+++ b/plug-ins/file-bmp/bmp-read.c
@@ -170,6 +170,7 @@ ReadBMP (const gchar  *name,
       g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                    _("'%s' is not a valid BMP file"),
                    gimp_filename_to_utf8 (filename));
+      fclose (fd);
       return -1;
     }
 
diff --git a/plug-ins/file-ico/ico-save.c b/plug-ins/file-ico/ico-save.c
index fe460b8..fbcfd79 100644
--- a/plug-ins/file-ico/ico-save.c
+++ b/plug-ins/file-ico/ico-save.c
@@ -1025,6 +1025,7 @@ ico_save_image (const gchar  *filename,
   if (fwrite (entries, sizeof (IcoFileEntry), info.num_icons, fp) <= 0)
     {
       ico_save_info_free (&info);
+      g_free (entries);
       fclose (fp);
       return GIMP_PDB_EXECUTION_ERROR;
     }
diff --git a/plug-ins/file-psd/psd-image-res-load.c b/plug-ins/file-psd/psd-image-res-load.c
index 945c876..3dd53dc 100644
--- a/plug-ins/file-psd/psd-image-res-load.c
+++ b/plug-ins/file-psd/psd-image-res-load.c
@@ -437,6 +437,7 @@ load_resource_unknown (const PSDimageres  *res_a,
   if (fread (data, res_a->data_len, 1, f) < 1)
     {
       psd_set_error (feof (f), errno, error);
+      g_free (data);
       return -1;
     }
 
@@ -471,6 +472,7 @@ load_resource_ps_only (const PSDimageres  *res_a,
   if (fread (data, res_a->data_len, 1, f) < 1)
     {
       psd_set_error (feof (f), errno, error);
+      g_free (data);
       return -1;
     }
 
@@ -800,6 +802,7 @@ load_resource_1028 (const PSDimageres  *res_a,
   if (fread (res_data, res_a->data_len, 1, f) < 1)
     {
       psd_set_error (feof (f), errno, error);
+      g_free (res_data);
       return -1;
     }
 
@@ -1067,6 +1070,7 @@ load_resource_1039 (const PSDimageres  *res_a,
   if (fread (icc_profile, res_a->data_len, 1, f) < 1)
     {
       psd_set_error (feof (f), errno, error);
+      g_free (icc_profile);
       return -1;
     }
 
@@ -1226,6 +1230,7 @@ load_resource_1058 (const PSDimageres  *res_a,
   if (fread (res_data, res_a->data_len, 1, f) < 1)
     {
       psd_set_error (feof (f), errno, error);
+      g_free (res_data);
       return -1;
     }
 
@@ -1336,6 +1341,7 @@ load_resource_1060 (const PSDimageres  *res_a,
   if (fread (res_data, res_a->data_len, 1, f) < 1)
     {
       psd_set_error (feof (f), errno, error);
+      g_free (res_data);
       return -1;
     }
   /* Null terminate metadata block for decode procedure */
@@ -1472,6 +1478,7 @@ load_resource_2000 (const PSDimageres  *res_a,
           if (fseek (f, 22, SEEK_CUR) < 0)
             {
               psd_set_error (feof (f), errno, error);
+              g_free (controlpoints);
               return -1;
             }
 
diff --git a/plug-ins/file-psd/psd-load.c b/plug-ins/file-psd/psd-load.c
index edfd30b..0071a40 100644
--- a/plug-ins/file-psd/psd-load.c
+++ b/plug-ins/file-psd/psd-load.c
@@ -1181,6 +1181,7 @@ add_layers (const gint32  image_id,
                             if (fread (&rle_pack_len[rowi], 2, 1, f) < 1)
                               {
                                 psd_set_error (feof (f), errno, error);
+                                g_free (rle_pack_len);
                                 return -1;
                               }
                             rle_pack_len[rowi] = GUINT16_FROM_BE (rle_pack_len[rowi]);
@@ -1846,6 +1847,8 @@ read_channel_data (PSDchannel     *channel,
             if (fread (src, rle_pack_len[i], 1, f) < 1)
               {
                 psd_set_error (feof (f), errno, error);
+                g_free (src);
+                g_free (dst);
                 return -1;
               }
             /* FIXME check for errors returned from decode packbits */
diff --git a/plug-ins/file-psd/psd-util.c b/plug-ins/file-psd/psd-util.c
index 619189c..cc45110 100644
--- a/plug-ins/file-psd/psd-util.c
+++ b/plug-ins/file-psd/psd-util.c
@@ -102,6 +102,7 @@ fread_pascal_string (gint32         *bytes_read,
   if (fread (str, len, 1, f) < 1)
     {
       psd_set_error (feof (f), errno, error);
+      g_free (str);
       return NULL;
     }
   *bytes_read += len;
@@ -247,6 +248,7 @@ fread_unicode_string (gint32         *bytes_read,
       if (fread (&utf16_str[i], 2, 1, f) < 1)
         {
           psd_set_error (feof (f), errno, error);
+          g_free (utf16_str);
           return NULL;
         }
       *bytes_read += 2;
diff --git a/plug-ins/fractal-explorer/fractal-explorer-dialogs.c b/plug-ins/fractal-explorer/fractal-explorer-dialogs.c
index 5fbc1f9..60bb99f 100644
--- a/plug-ins/fractal-explorer/fractal-explorer-dialogs.c
+++ b/plug-ins/fractal-explorer/fractal-explorer-dialogs.c
@@ -1869,12 +1869,14 @@ explorer_load (void)
     {
       g_message (_("'%s' is not a FractalExplorer file"),
                  gimp_filename_to_utf8 (filename));
+      fclose (fp);
       return;
     }
   if (load_options (current_obj,fp))
     {
       g_message (_("'%s' is corrupt. Line %d Option section incorrect"),
                  gimp_filename_to_utf8 (filename), line_no);
+      fclose (fp);
       return;
     }
 
diff --git a/plug-ins/fractal-explorer/fractal-explorer.c b/plug-ins/fractal-explorer/fractal-explorer.c
index 5d1eca2..9c75a1f 100644
--- a/plug-ins/fractal-explorer/fractal-explorer.c
+++ b/plug-ins/fractal-explorer/fractal-explorer.c
@@ -949,6 +949,7 @@ fractalexplorer_load (const gchar *filename,
       g_message (_("File '%s' is not a FractalExplorer file"),
                  gimp_filename_to_utf8 (filename));
       fclose (fp);
+      fractalexplorer_free (fractalexplorer);
 
       return NULL;
     }
@@ -958,6 +959,7 @@ fractalexplorer_load (const gchar *filename,
       g_message (_("File '%s' is corrupt.\nLine %d Option section incorrect"),
                  gimp_filename_to_utf8 (filename), line_no);
       fclose (fp);
+      fractalexplorer_free (fractalexplorer);
 
       return NULL;
     }
diff --git a/plug-ins/gfig/gfig.c b/plug-ins/gfig/gfig.c
index 7ff8520..d2f5ce9 100644
--- a/plug-ins/gfig/gfig.c
+++ b/plug-ins/gfig/gfig.c
@@ -456,6 +456,7 @@ gfig_load (const gchar *filename,
     {
       g_message ("File '%s' is not a gfig file",
                   gimp_filename_to_utf8 (gfig->filename));
+      gfig_free (gfig);
       return NULL;
     }
 
@@ -475,6 +476,7 @@ gfig_load (const gchar *filename,
     {
       g_message ("File '%s' corrupt file - Line %d Option section incorrect",
                  gimp_filename_to_utf8 (filename), line_no);
+      gfig_free (gfig);
       return NULL;
     }
 
@@ -482,6 +484,7 @@ gfig_load (const gchar *filename,
     {
       g_message ("File '%s' corrupt file - Line %d Option section incorrect",
                  gimp_filename_to_utf8 (filename), line_no);
+      gfig_free (gfig);
       return NULL;
     }
 
@@ -497,6 +500,7 @@ gfig_load (const gchar *filename,
     {
       g_message ("File '%s' corrupt file - Line %d Object count to small",
                  gimp_filename_to_utf8 (filename), line_no);
+      gfig_free (gfig);
       return NULL;
     }
 
diff --git a/plug-ins/gimpressionist/ppmtool.c b/plug-ins/gimpressionist/ppmtool.c
index 5c8a68f..8af3fcd 100644
--- a/plug-ins/gimpressionist/ppmtool.c
+++ b/plug-ins/gimpressionist/ppmtool.c
@@ -339,6 +339,7 @@ ppm_load (const char *fn, ppm_t *p)
   readline (f, line, 200);
   if (strcmp (line, "255"))
   {
+    fclose (f);
     g_printerr ("ppm_load: File \"%s\" not valid PPM/PGM? (line=\"%s\")%c\n",
                 gimp_filename_to_utf8 (fn), line, 7);
     ppm_new (p, 10,10);
diff --git a/plug-ins/ifs-compose/ifs-compose-utils.c b/plug-ins/ifs-compose/ifs-compose-utils.c
index 4e2a355..be61eec 100644
--- a/plug-ins/ifs-compose/ifs-compose-utils.c
+++ b/plug-ins/ifs-compose/ifs-compose-utils.c
@@ -264,6 +264,7 @@ ipolygon_convex_hull (IPolygon *poly)
     {
       memcpy (new_points, poly->points, num_new * sizeof (GdkPoint));
       new_poly->npoints = num_new;
+      g_free (sort_points);
       return new_poly;
     }
 



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