[gimp] plug-ins: more replacement of g_file_get_path() to g_file_peek_path().



commit 4ae3687c8801122bee924b4dde21900d7a137688
Author: Jehan <jehan girinstud io>
Date:   Fri Oct 1 18:56:12 2021 +0200

    plug-ins: more replacement of g_file_get_path() to g_file_peek_path().
    
    While doing this cleanup, I found at least several other string leaks
    in: file-compressor, file-gegl, file-pdf-save, file-raw-data, file-xwd,
    jpeg-load, psd-saveā€¦
    So it's quite worth it!
    
    Note: in file-pdf-save, there is a global variable file_name which seems
    to be happily leaked without caring (didn't look in details, but looks
    so). I didn't fix this one which will require a bit more in-depth logics
    care.

 plug-ins/common/file-cel.c        | 10 ++----
 plug-ins/common/file-compressor.c | 71 +++++++++------------------------------
 plug-ins/common/file-dicom.c      | 10 ++----
 plug-ins/common/file-gegl.c       | 10 ++----
 plug-ins/common/file-pcx.c        | 10 ++----
 plug-ins/common/file-pdf-save.c   |  2 +-
 plug-ins/common/file-ps.c         | 15 ++-------
 plug-ins/common/file-psp.c        | 10 ++----
 plug-ins/common/file-raw-data.c   | 32 +++++-------------
 plug-ins/common/file-tga.c        | 10 ++----
 plug-ins/common/file-xwd.c        |  7 ++--
 plug-ins/common/mail.c            |  5 +--
 plug-ins/file-bmp/bmp-load.c      |  5 +--
 plug-ins/file-bmp/bmp-save.c      |  5 +--
 plug-ins/file-dds/ddsread.c       |  5 +--
 plug-ins/file-jpeg/jpeg-load.c    |  7 ++--
 plug-ins/file-jpeg/jpeg-save.c    |  5 +--
 plug-ins/file-psd/psd-save.c      |  5 ++-
 18 files changed, 50 insertions(+), 174 deletions(-)
---
diff --git a/plug-ins/common/file-cel.c b/plug-ins/common/file-cel.c
index da4667284d..f959190a0e 100644
--- a/plug-ins/common/file-cel.c
+++ b/plug-ins/common/file-cel.c
@@ -340,14 +340,11 @@ static gboolean
 need_palette (GFile   *file,
               GError **error)
 {
-  gchar  *filename;
   FILE   *fp;
   guchar  header[32];
   size_t  n_read;
 
-  filename = g_file_get_path (file);
-  fp = g_fopen (filename, "rb");
-  g_free (filename);
+  fp = g_fopen (g_file_peek_path (file), "rb");
 
   if (! fp)
     {
@@ -377,7 +374,6 @@ static GimpImage *
 load_image (GFile   *file,
             GError **error)
 {
-  gchar      *filename;
   FILE       *fp;            /* Read file pointer */
   guchar      header[32],    /* File header */
               file_mark,     /* KiSS file type */
@@ -399,9 +395,7 @@ load_image (GFile   *file,
                              gimp_file_get_utf8_name (file));
 
   /* Open the file for reading */
-  filename = g_file_get_path (file);
-  fp = g_fopen (filename, "r");
-  g_free (filename);
+  fp = g_fopen (g_file_peek_path (file), "r");
 
   if (fp == NULL)
     {
diff --git a/plug-ins/common/file-compressor.c b/plug-ins/common/file-compressor.c
index 747f932143..f21a567d4d 100644
--- a/plug-ins/common/file-compressor.c
+++ b/plug-ins/common/file-compressor.c
@@ -426,11 +426,10 @@ save_image (const CompressorEntry  *compressor,
             gint32                  run_mode,
             GError                **error)
 {
-  gchar       *filename = g_file_get_path (file);
   const gchar *ext;
   GFile       *tmp_file;
 
-  ext = find_extension (compressor, filename);
+  ext = find_extension (compressor, g_file_peek_path (file));
 
   if (! ext)
     {
@@ -451,7 +450,6 @@ save_image (const CompressorEntry  *compressor,
     {
       g_file_delete (tmp_file, NULL, NULL);
       g_object_unref (tmp_file);
-      g_free (filename);
 
       g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
                    "%s", gimp_pdb_get_last_error (gimp_get_pdb ()));
@@ -466,7 +464,6 @@ save_image (const CompressorEntry  *compressor,
     {
       g_file_delete (tmp_file, NULL, NULL);
       g_object_unref (tmp_file);
-      g_free (filename);
 
       return GIMP_PDB_EXECUTION_ERROR;
     }
@@ -480,8 +477,6 @@ save_image (const CompressorEntry  *compressor,
   if (strcmp (ext, ".xcf") == 0)
     gimp_file_save_thumbnail (image, file);
 
-  g_free (filename);
-
   return GIMP_PDB_SUCCESS;
 }
 
@@ -493,13 +488,10 @@ load_image (const CompressorEntry  *compressor,
             GError                **error)
 {
   GimpImage   *image;
-  gchar       *filename;
   const gchar *ext;
   GFile       *tmp_file;
 
-  filename = g_file_get_path (file);
-
-  ext = find_extension (compressor, filename);
+  ext = find_extension (compressor, g_file_peek_path (file));
 
   if (! ext)
     {
@@ -514,13 +506,10 @@ load_image (const CompressorEntry  *compressor,
   if (! compressor->load_fn (file, tmp_file))
     {
       g_object_unref (tmp_file);
-      g_free (filename);
       *status = GIMP_PDB_EXECUTION_ERROR;
       return NULL;
     }
 
-  g_free (filename);
-
   /* now that we uncompressed it, load the temp file */
 
   image = gimp_file_load (run_mode, tmp_file);
@@ -551,13 +540,10 @@ load_image (const CompressorEntry  *compressor,
 static gboolean
 valid_file (GFile *file)
 {
-  gchar    *filename;
   GStatBuf  buf;
   gboolean  valid;
 
-  filename = g_file_get_path (file);
-  valid = g_stat (filename, &buf) == 0 && buf.st_size > 0;
-  g_free (filename);
+  valid = g_stat (g_file_peek_path (file), &buf) == 0 && buf.st_size > 0;
 
   return valid;
 }
@@ -603,8 +589,6 @@ static gboolean
 gzip_load (GFile *infile,
            GFile *outfile)
 {
-  gchar    *in_filename  = g_file_get_path (infile);
-  gchar    *out_filename = g_file_get_path (outfile);
   gboolean  ret;
   int       fd;
   gzFile    in;
@@ -616,7 +600,7 @@ gzip_load (GFile *infile,
   in = NULL;
   out = NULL;
 
-  fd = g_open (in_filename, O_RDONLY | _O_BINARY, 0);
+  fd = g_open (g_file_peek_path (infile), O_RDONLY | _O_BINARY, 0);
   if (fd == -1)
     goto out;
 
@@ -627,7 +611,7 @@ gzip_load (GFile *infile,
       goto out;
     }
 
-  out = g_fopen (out_filename, "wb");
+  out = g_fopen (g_file_peek_path (outfile), "wb");
   if (! out)
     goto out;
 
@@ -656,9 +640,6 @@ gzip_load (GFile *infile,
   if (out)
     fclose (out);
 
-  g_free (in_filename);
-  g_free (out_filename);
-
   return ret;
 }
 
@@ -666,8 +647,6 @@ static gboolean
 gzip_save (GFile *infile,
            GFile *outfile)
 {
-  gchar    *in_filename  = g_file_get_path (infile);
-  gchar    *out_filename = g_file_get_path (outfile);
   gboolean  ret;
   FILE     *in;
   int       fd;
@@ -680,11 +659,11 @@ gzip_save (GFile *infile,
   in = NULL;
   out = NULL;
 
-  in = g_fopen (in_filename, "rb");
+  in = g_fopen (g_file_peek_path (infile), "rb");
   if (! in)
     goto out;
 
-  fd = g_open (out_filename, O_CREAT | O_WRONLY | O_TRUNC | _O_BINARY, 0664);
+  fd = g_open (g_file_peek_path (outfile), O_CREAT | O_WRONLY | O_TRUNC | _O_BINARY, 0664);
   if (fd == -1)
     goto out;
 
@@ -732,8 +711,6 @@ static gboolean
 bzip2_load (GFile *infile,
            GFile  *outfile)
 {
-  gchar    *in_filename  = g_file_get_path (infile);
-  gchar    *out_filename = g_file_get_path (outfile);
   gboolean  ret;
   int       fd;
   BZFILE   *in;
@@ -745,7 +722,7 @@ bzip2_load (GFile *infile,
   in = NULL;
   out = NULL;
 
-  fd = g_open (in_filename, O_RDONLY | _O_BINARY, 0);
+  fd = g_open (g_file_peek_path (infile), O_RDONLY | _O_BINARY, 0);
   if (fd == -1)
     goto out;
 
@@ -756,7 +733,7 @@ bzip2_load (GFile *infile,
       goto out;
     }
 
-  out = g_fopen (out_filename, "wb");
+  out = g_fopen (g_file_peek_path (outfile), "wb");
   if (!out)
     goto out;
 
@@ -785,9 +762,6 @@ bzip2_load (GFile *infile,
   if (out)
     fclose (out);
 
-  g_free (in_filename);
-  g_free (out_filename);
-
   return ret;
 }
 
@@ -795,8 +769,6 @@ static gboolean
 bzip2_save (GFile *infile,
             GFile *outfile)
 {
-  gchar    *in_filename  = g_file_get_path (infile);
-  gchar    *out_filename = g_file_get_path (outfile);
   gboolean  ret;
   FILE     *in;
   int       fd;
@@ -809,11 +781,11 @@ bzip2_save (GFile *infile,
   in = NULL;
   out = NULL;
 
-  in = g_fopen (in_filename, "rb");
+  in = g_fopen (g_file_peek_path (infile), "rb");
   if (!in)
     goto out;
 
-  fd = g_open (out_filename, O_CREAT | O_WRONLY | O_TRUNC | _O_BINARY, 0664);
+  fd = g_open (g_file_peek_path (outfile), O_CREAT | O_WRONLY | O_TRUNC | _O_BINARY, 0664);
   if (fd == -1)
     goto out;
 
@@ -854,9 +826,6 @@ bzip2_save (GFile *infile,
   if (out)
     BZ2_bzclose (out);
 
-  g_free (in_filename);
-  g_free (out_filename);
-
   return ret;
 }
 
@@ -864,8 +833,6 @@ static gboolean
 xz_load (GFile *infile,
          GFile *outfile)
 {
-  gchar       *in_filename  = g_file_get_path (infile);
-  gchar       *out_filename = g_file_get_path (outfile);
   gboolean     ret;
   FILE        *in;
   FILE        *out;
@@ -879,11 +846,11 @@ xz_load (GFile *infile,
   in = NULL;
   out = NULL;
 
-  in = g_fopen (in_filename, "rb");
+  in = g_fopen (g_file_peek_path (infile), "rb");
   if (!in)
     goto out;
 
-  out = g_fopen (out_filename, "wb");
+  out = g_fopen (g_file_peek_path (outfile), "wb");
   if (!out)
     goto out;
 
@@ -947,9 +914,6 @@ xz_load (GFile *infile,
   if (out)
     fclose (out);
 
-  g_free (in_filename);
-  g_free (out_filename);
-
   return ret;
 }
 
@@ -957,8 +921,6 @@ static gboolean
 xz_save (GFile *infile,
          GFile *outfile)
 {
-  gchar       *in_filename  = g_file_get_path (infile);
-  gchar       *out_filename = g_file_get_path (outfile);
   gboolean     ret;
   FILE        *in;
   FILE        *out;
@@ -973,12 +935,12 @@ xz_save (GFile *infile,
   in = NULL;
   out = NULL;
 
-  in = g_fopen (in_filename, "rb");
+  in = g_fopen (g_file_peek_path (infile), "rb");
   if (!in)
     goto out;
 
   file_size = get_file_info (infile);
-  out = g_fopen (out_filename, "wb");
+  out = g_fopen (g_file_peek_path (outfile), "wb");
   if (!out)
     goto out;
 
@@ -1046,9 +1008,6 @@ xz_save (GFile *infile,
   if (out)
     fclose (out);
 
-  g_free (in_filename);
-  g_free (out_filename);
-
   return ret;
 }
 
diff --git a/plug-ins/common/file-dicom.c b/plug-ins/common/file-dicom.c
index 3a6f0669e7..2d2a160c2a 100644
--- a/plug-ins/common/file-dicom.c
+++ b/plug-ins/common/file-dicom.c
@@ -349,7 +349,6 @@ load_image (GFile   *file,
   GimpImage  *image = NULL;
   GimpLayer  *layer;
   GeglBuffer *buffer;
-  gchar      *filename;
   GSList     *elements          = NULL;
   FILE       *dicom;
   gchar       buf[500];    /* buffer for random things like scanning */
@@ -369,9 +368,7 @@ load_image (GFile   *file,
   gimp_progress_init_printf (_("Opening '%s'"),
                              gimp_file_get_utf8_name (file));
 
-  filename = g_file_get_path (file);
-  dicom = g_fopen (filename, "rb");
-  g_free (filename);
+  dicom = g_fopen (g_file_peek_path (file), "rb");
 
   if (! dicom)
     {
@@ -1444,7 +1441,6 @@ save_image (GFile        *file,
             GimpDrawable *drawable,
             GError      **error)
 {
-  gchar         *filename;
   FILE          *dicom;
   GimpImageType  drawable_type;
   GeglBuffer    *buffer;
@@ -1499,9 +1495,7 @@ save_image (GFile        *file,
   g_date_free (date);
 
   /* Open the output file. */
-  filename = g_file_get_path (file);
-  dicom = g_fopen (filename, "wb");
-  g_free (filename);
+  dicom = g_fopen (g_file_peek_path (file), "wb");
 
   if (! dicom)
     {
diff --git a/plug-ins/common/file-gegl.c b/plug-ins/common/file-gegl.c
index 2c020ef844..8b497a6a01 100644
--- a/plug-ins/common/file-gegl.c
+++ b/plug-ins/common/file-gegl.c
@@ -327,7 +327,6 @@ load_image (GFile   *file,
 {
   GimpImage         *image;
   GimpLayer         *layer;
-  gchar             *filename;
   GimpImageType      image_type;
   GimpImageBaseType  base_type;
   GimpPrecision      precision;
@@ -340,8 +339,6 @@ load_image (GFile   *file,
   GeglBuffer        *dest_buf = NULL;
   const Babl        *format;
 
-  filename = g_file_get_path (file);
-
   gimp_progress_init_printf (_("Opening '%s'"),
                              gimp_file_get_utf8_name (file));
 
@@ -349,7 +346,7 @@ load_image (GFile   *file,
 
   source = gegl_node_new_child (graph,
                                 "operation", "gegl:load",
-                                "path",      filename,
+                                "path",      g_file_peek_path (file),
                                 NULL);
   sink = gegl_node_new_child (graph,
                               "operation", "gegl:buffer-sink",
@@ -485,14 +482,11 @@ save_image (GFile         *file,
             GimpDrawable  *drawable,
             GError       **error)
 {
-  gchar      *filename;
   GeglNode   *graph;
   GeglNode   *source;
   GeglNode   *sink;
   GeglBuffer *src_buf;
 
-  filename = g_file_get_path (file);
-
   src_buf = gimp_drawable_get_buffer (drawable);
 
   graph = gegl_node_new ();
@@ -503,7 +497,7 @@ save_image (GFile         *file,
                                 NULL);
   sink = gegl_node_new_child (graph,
                               "operation", "gegl:save",
-                              "path",      filename,
+                              "path",      g_file_peek_path (file),
                               NULL);
 
   gegl_node_connect_to (source, "output",
diff --git a/plug-ins/common/file-pcx.c b/plug-ins/common/file-pcx.c
index 2f55dbbaba..59ad737b0a 100644
--- a/plug-ins/common/file-pcx.c
+++ b/plug-ins/common/file-pcx.c
@@ -391,7 +391,6 @@ load_image (GFile   *file,
 {
   FILE         *fd;
   GeglBuffer   *buffer;
-  gchar        *filename;
   guint16       offset_x, offset_y, bytesperline;
   gint32        width, height;
   guint16       resolution_x, resolution_y;
@@ -403,9 +402,7 @@ load_image (GFile   *file,
   gimp_progress_init_printf (_("Opening '%s'"),
                              gimp_file_get_utf8_name (file));
 
-  filename = g_file_get_path (file);
-  fd = g_fopen (filename, "rb");
-  g_free (filename);
+  fd = g_fopen (g_file_peek_path (file), "rb");
 
   if (! fd)
     {
@@ -774,7 +771,6 @@ save_image (GFile         *file,
 {
   FILE          *fp;
   GeglBuffer    *buffer;
-  gchar         *filename;
   const Babl    *format;
   GimpImageType  drawable_type;
   guchar        *cmap= NULL;
@@ -904,9 +900,7 @@ save_image (GFile         *file,
       return FALSE;
     }
 
-  filename = g_file_get_path (file);
-  fp = g_fopen (filename, "wb");
-  g_free (filename);
+  fp = g_fopen (g_file_peek_path (file), "wb");
 
   if (! fp)
     {
diff --git a/plug-ins/common/file-pdf-save.c b/plug-ins/common/file-pdf-save.c
index 3adbf15c1f..5890a8c909 100644
--- a/plug-ins/common/file-pdf-save.c
+++ b/plug-ins/common/file-pdf-save.c
@@ -1292,7 +1292,7 @@ choose_file_call (GtkWidget *browse_button,
   if (gtk_dialog_run (GTK_DIALOG (file_choose)) == GTK_RESPONSE_OK)
     {
       file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (file_choose));
-      gtk_entry_set_text (GTK_ENTRY (file_entry), g_file_get_path (file));
+      gtk_entry_set_text (GTK_ENTRY (file_entry), g_file_peek_path (file));
     }
 
   file_name = g_file_get_path (file);
diff --git a/plug-ins/common/file-ps.c b/plug-ins/common/file-ps.c
index a5657c42f9..d6f92e1e23 100644
--- a/plug-ins/common/file-ps.c
+++ b/plug-ins/common/file-ps.c
@@ -1655,14 +1655,11 @@ get_bbox (GFile *file,
           gint  *x1,
           gint  *y1)
 {
-  gchar *filename;
   char   line[1024], *src;
   FILE  *ifp;
   int    retval = -1;
 
-  filename = g_file_get_path (file);
-  ifp = g_fopen (filename, "rb");
-  g_free (filename);
+  ifp = g_fopen (g_file_peek_path (file), "rb");
 
   if (! ifp)
     return -1;
@@ -3465,16 +3462,13 @@ print (GOutputStream  *output,
 static gint32
 count_ps_pages (GFile *file)
 {
-  gchar  *filename;
   FILE   *psfile;
   gchar  *extension;
   gchar   buf[1024];
   gint32  num_pages      = 0;
   gint32  showpage_count = 0;
 
-  filename = g_file_get_path (file);
-
-  extension = strrchr (filename, '.');
+  extension = strrchr (g_file_peek_path (file), '.');
   if (extension)
     {
       extension = g_ascii_strdown (extension + 1, -1);
@@ -3482,16 +3476,13 @@ count_ps_pages (GFile *file)
       if (strcmp (extension, "eps") == 0)
         {
           g_free (extension);
-          g_free (filename);
           return 1;
         }
 
       g_free (extension);
     }
 
-  psfile = g_fopen (filename, "r");
-
-  g_free (filename);
+  psfile = g_fopen (g_file_peek_path (file), "r");
 
   if (psfile == NULL)
     {
diff --git a/plug-ins/common/file-psp.c b/plug-ins/common/file-psp.c
index 23872ccae4..f891ca1856 100644
--- a/plug-ins/common/file-psp.c
+++ b/plug-ins/common/file-psp.c
@@ -2358,7 +2358,6 @@ static GimpImage *
 load_image (GFile   *file,
             GError **error)
 {
-  gchar     *filename;
   FILE      *f;
   GStatBuf   st;
   char       buf[32];
@@ -2370,17 +2369,12 @@ load_image (GFile   *file,
 
   GimpImage *image = NULL;
 
-  filename = g_file_get_path (file);
-
-  if (g_stat (filename, &st) == -1)
+  if (g_stat (g_file_peek_path (file), &st) == -1)
     {
-      g_free (filename);
       return NULL;
     }
 
-  f = g_fopen (filename, "rb");
-
-  g_free (filename);
+  f = g_fopen (g_file_peek_path (file), "rb");
 
   if (! f)
     {
diff --git a/plug-ins/common/file-raw-data.c b/plug-ins/common/file-raw-data.c
index bcba851a33..3b5b6ae320 100644
--- a/plug-ins/common/file-raw-data.c
+++ b/plug-ins/common/file-raw-data.c
@@ -377,7 +377,7 @@ raw_load (GimpProcedure        *procedure,
 
       runtime->image_type = RAW_GRAY_16BPP_SBE;
 
-      fp = g_fopen (g_file_get_path (file), "rb");
+      fp = g_fopen (g_file_peek_path (file), "rb");
       if (! fp)
         {
           g_set_error (&error, G_FILE_ERROR, g_file_error_from_errno (errno),
@@ -431,7 +431,7 @@ raw_load (GimpProcedure        *procedure,
       if (! is_hgt)
         gimp_get_data (LOAD_PROC, runtime);
 
-      preview_fd = g_open (g_file_get_path (file), O_RDONLY, 0);
+      preview_fd = g_open (g_file_peek_path (file), O_RDONLY, 0);
       if (preview_fd < 0)
         {
           g_set_error (&error,
@@ -990,11 +990,7 @@ raw_load_palette (RawGimpData *data,
 
   if (palette_file)
     {
-      gchar *filename;
-
-      filename = g_file_get_path (palette_file);
-      fd = g_open (filename, O_RDONLY, 0);
-      g_free (filename);
+      fd = g_open (g_file_peek_path (palette_file), O_RDONLY, 0);
 
       if (! fd)
         return FALSE;
@@ -1046,7 +1042,6 @@ save_image (GFile         *file,
             GError       **error)
 {
   GeglBuffer     *buffer;
-  gchar          *filename;
   const Babl     *format = NULL;
   guchar         *cmap   = NULL;  /* colormap for indexed images */
   guchar         *buf;
@@ -1108,15 +1103,13 @@ save_image (GFile         *file,
 
   g_object_unref (buffer);
 
-  filename = g_file_get_path (file);
-  fp = g_fopen (filename, "wb");
+  fp = g_fopen (g_file_peek_path (file), "wb");
 
   if (! fp)
     {
       g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
                    _("Could not open '%s' for writing: %s"),
                    gimp_file_get_utf8_name (file), g_strerror (errno));
-      g_free (filename);
       return FALSE;
     }
 
@@ -1136,7 +1129,7 @@ save_image (GFile         *file,
       if (cmap)
         {
           /* we have colormap, too.write it into filename+pal */
-          gchar *newfile = g_strconcat (filename, ".pal", NULL);
+          gchar *newfile = g_strconcat (g_file_peek_path (file), ".pal", NULL);
           gchar *temp;
 
           fp = g_fopen (newfile, "wb");
@@ -1146,7 +1139,6 @@ save_image (GFile         *file,
               g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
                            _("Could not open '%s' for writing: %s"),
                            gimp_filename_to_utf8 (newfile), g_strerror (errno));
-              g_free (filename);
               return FALSE;
             }
 
@@ -1203,8 +1195,6 @@ save_image (GFile         *file,
       break;
     }
 
-  g_free (filename);
-
   return ret;
 }
 
@@ -1214,7 +1204,6 @@ load_image (GFile   *file,
 {
   RawGimpData       *data;
   GimpLayer         *layer = NULL;
-  gchar             *filename;
   GimpImageType      ltype = GIMP_RGB_IMAGE;
   GimpImageBaseType  itype = GIMP_RGB;
   goffset            size;
@@ -1226,9 +1215,7 @@ load_image (GFile   *file,
   gimp_progress_init_printf (_("Opening '%s'"),
                              gimp_file_get_utf8_name (file));
 
-  filename = g_file_get_path (file);
-  data->fp = g_fopen (filename, "rb");
-  g_free (filename);
+  data->fp = g_fopen (g_file_peek_path (file), "rb");
 
   if (! data->fp)
     {
@@ -1600,12 +1587,9 @@ preview_update (GimpPreviewArea *preview)
           {
             if (palfile)
               {
-                gchar *filename;
-                gint   fd;
+                gint fd;
 
-                filename = g_file_get_path (palfile);
-                fd = g_open (filename, O_RDONLY, 0);
-                g_free (filename);
+                fd = g_open (g_file_peek_path (palfile), O_RDONLY, 0);
 
                 lseek (fd, runtime->palette_offset, SEEK_SET);
                 read (fd, preview_cmap,
diff --git a/plug-ins/common/file-tga.c b/plug-ins/common/file-tga.c
index e6f9e41502..09aab84f9f 100644
--- a/plug-ins/common/file-tga.c
+++ b/plug-ins/common/file-tga.c
@@ -426,7 +426,6 @@ static GimpImage *
 load_image (GFile   *file,
             GError **error)
 {
-  gchar     *filename;
   FILE      *fp;
   tga_info   info;
   guchar     header[18];
@@ -438,9 +437,7 @@ load_image (GFile   *file,
   gimp_progress_init_printf (_("Opening '%s'"),
                              gimp_file_get_utf8_name (file));
 
-  filename = g_file_get_path (file);
-  fp = g_fopen (filename, "rb");
-  g_free (filename);
+  fp = g_fopen (g_file_peek_path (file), "rb");
 
   if (! fp)
     {
@@ -1195,7 +1192,6 @@ save_image (GFile         *file,
   GimpImageType  dtype;
   gint           width;
   gint           height;
-  gchar         *filename;
   FILE          *fp;
   gint           out_bpp = 0;
   gboolean       status  = TRUE;
@@ -1224,9 +1220,7 @@ save_image (GFile         *file,
   gimp_progress_init_printf (_("Exporting '%s'"),
                              gimp_file_get_utf8_name (file));
 
-  filename = g_file_get_path (file);
-  fp = g_fopen (filename, "wb");
-  g_free (filename);
+  fp = g_fopen (g_file_peek_path (file), "wb");
 
   if (! fp)
     {
diff --git a/plug-ins/common/file-xwd.c b/plug-ins/common/file-xwd.c
index c6d6e1f47b..9056e0f937 100644
--- a/plug-ins/common/file-xwd.c
+++ b/plug-ins/common/file-xwd.c
@@ -464,7 +464,6 @@ static GimpImage *
 load_image (GFile   *file,
             GError **error)
 {
-  gchar           *filename;
   FILE            *ifp;
   gint             depth, bpp;
   GimpImage       *image = NULL;
@@ -474,9 +473,7 @@ load_image (GFile   *file,
   gimp_progress_init_printf (_("Opening '%s'"),
                              gimp_file_get_utf8_name (file));
 
-  filename = g_file_get_path (file);
-  ifp = g_fopen (filename, "rb");
-  g_free (filename);
+  ifp = g_fopen (g_file_peek_path (file), "rb");
 
   if (! ifp)
     {
@@ -533,7 +530,7 @@ load_image (GFile   *file,
 #ifdef XWD_COL_DEBUG
       {
         int j;
-        g_printf ("File %s\n", g_file_get_path (file));
+        g_printf ("File %s\n", g_file_peek_path (file));
         for (j = 0; j < xwdhdr.l_colormap_entries; j++)
           g_printf ("Entry 0x%08lx: 0x%04lx,  0x%04lx, 0x%04lx, %d\n",
                     (long)xwdcolmap[j].l_pixel,(long)xwdcolmap[j].l_red,
diff --git a/plug-ins/common/mail.c b/plug-ins/common/mail.c
index 7278f97c4f..690e8f8ead 100644
--- a/plug-ins/common/mail.c
+++ b/plug-ins/common/mail.c
@@ -681,13 +681,10 @@ send_dialog (void)
 static gboolean
 valid_file (GFile *file)
 {
-  gchar    *filename;
   GStatBuf  buf;
   gboolean  valid;
 
-  filename = g_file_get_path (file);
-  valid = g_stat (filename, &buf) == 0 && buf.st_size > 0;
-  g_free (filename);
+  valid = g_stat (g_file_peek_path (file), &buf) == 0 && buf.st_size > 0;
 
   return valid;
 }
diff --git a/plug-ins/file-bmp/bmp-load.c b/plug-ins/file-bmp/bmp-load.c
index df8f26c048..fd2e79fc72 100644
--- a/plug-ins/file-bmp/bmp-load.c
+++ b/plug-ins/file-bmp/bmp-load.c
@@ -204,7 +204,6 @@ GimpImage *
 load_image (GFile  *file,
             GError **error)
 {
-  gchar          *filename;
   FILE           *fd;
   BitmapFileHead  bitmap_file_head;
   BitmapHead      bitmap_head;
@@ -219,9 +218,7 @@ load_image (GFile  *file,
   gimp_progress_init_printf (_("Opening '%s'"),
                              gimp_file_get_utf8_name (file));
 
-  filename = g_file_get_path (file);
-  fd = g_fopen (filename, "rb");
-  g_free (filename);
+  fd = g_fopen (g_file_peek_path (file), "rb");
 
   if (! fd)
     {
diff --git a/plug-ins/file-bmp/bmp-save.c b/plug-ins/file-bmp/bmp-save.c
index 07676506f4..9b98b4a310 100644
--- a/plug-ins/file-bmp/bmp-save.c
+++ b/plug-ins/file-bmp/bmp-save.c
@@ -125,7 +125,6 @@ save_image (GFile         *file,
             GObject       *config,
             GError       **error)
 {
-  gchar          *filename;
   FILE           *outfile;
   BitmapFileHead  bitmap_file_head;
   BitmapHead      bitmap_head;
@@ -333,9 +332,7 @@ save_image (GFile         *file,
   gimp_progress_init_printf (_("Exporting '%s'"),
                              gimp_file_get_utf8_name (file));
 
-  filename = g_file_get_path (file);
-  outfile = g_fopen (filename, "wb");
-  g_free (filename);
+  outfile = g_fopen (g_file_peek_path (file), "wb");
 
   if (! outfile)
     {
diff --git a/plug-ins/file-dds/ddsread.c b/plug-ins/file-dds/ddsread.c
index 8acf616ee7..72102d0e1c 100644
--- a/plug-ins/file-dds/ddsread.c
+++ b/plug-ins/file-dds/ddsread.c
@@ -123,7 +123,6 @@ read_dds (GFile          *file,
   guchar            *buf;
   guint              l = 0;
   guchar            *pixels;
-  gchar             *filename;
   FILE              *fp;
   dds_header_t       hdr;
   dds_header_dx10_t  dx10hdr;
@@ -148,9 +147,7 @@ read_dds (GFile          *file,
                 "decode-images", &decode_images,
                 NULL);
 
-  filename = g_file_get_path (file);
-  fp = g_fopen (filename, "rb");
-  g_free (filename);
+  fp = g_fopen (g_file_peek_path (file), "rb");
 
   if (! fp)
     {
diff --git a/plug-ins/file-jpeg/jpeg-load.c b/plug-ins/file-jpeg/jpeg-load.c
index 7ca3324c7f..e7b4503122 100644
--- a/plug-ins/file-jpeg/jpeg-load.c
+++ b/plug-ins/file-jpeg/jpeg-load.c
@@ -67,7 +67,6 @@ load_image (GFile        *file,
   struct jpeg_decompress_struct cinfo;
   struct my_error_mgr           jerr;
   jpeg_saved_marker_ptr         marker;
-  gchar             *filename;
   FILE              *infile;
   guchar            *buf;
   guchar           **rowbuf;
@@ -92,9 +91,7 @@ load_image (GFile        *file,
                                  gimp_file_get_utf8_name (file));
     }
 
-  filename = g_file_get_path (file);
-  infile = g_fopen (filename, "rb");
-  g_free (filename);
+  infile = g_fopen (g_file_peek_path (file), "rb");
 
   if (! infile)
     {
@@ -537,7 +534,7 @@ load_thumbnail_image (GFile         *file,
   jerr.pub.error_exit     = my_error_exit;
   jerr.pub.output_message = my_output_message;
 
-  if ((infile = g_fopen (g_file_get_path (file), "rb")) == NULL)
+  if ((infile = g_fopen (g_file_peek_path (file), "rb")) == NULL)
     {
       g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
                    _("Could not open '%s' for reading: %s"),
diff --git a/plug-ins/file-jpeg/jpeg-save.c b/plug-ins/file-jpeg/jpeg-save.c
index 713031483e..557ef6fe51 100644
--- a/plug-ins/file-jpeg/jpeg-save.c
+++ b/plug-ins/file-jpeg/jpeg-save.c
@@ -210,7 +210,6 @@ save_image (GFile                *file,
   const Babl       *format;
   const Babl       *space;
   JpegSubsampling   subsampling;
-  gchar            *filename;
   FILE             * volatile outfile;
   guchar           *data;
   guchar           *src;
@@ -307,9 +306,7 @@ save_image (GFile                *file,
    * VERY IMPORTANT: use "b" option to fopen() if you are on a machine that
    * requires it in order to write binary files.
    */
-  filename = g_file_get_path (file);
-  outfile = g_fopen (filename, "wb");
-  g_free (filename);
+  outfile = g_fopen (g_file_peek_path (file), "wb");
 
   if (! outfile)
     {
diff --git a/plug-ins/file-psd/psd-save.c b/plug-ins/file-psd/psd-save.c
index 9ba232ac60..fd8c851e16 100644
--- a/plug-ins/file-psd/psd-save.c
+++ b/plug-ins/file-psd/psd-save.c
@@ -620,7 +620,6 @@ save_resources (GOutputStream  *output,
 {
   GList        *iter;
   gint          i;
-  gchar        *fileName;            /* Image file name */
   GList        *SelLayers;           /* The selected layers */
 
   goffset       eof_pos;             /* Position for End of file */
@@ -637,8 +636,8 @@ save_resources (GOutputStream  *output,
 
   /* Get the image title from its filename */
 
-  fileName = g_file_get_path (gimp_image_get_file (image));
-  IFDBG printf ("\tImage title: %s\n", fileName);
+  IFDBG printf ("\tImage title: %s\n",
+                g_file_peek_path (gimp_image_get_file (image)));
 
   /* Get the selected layers */
 


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