Commit 4ae3687c authored by Jehan's avatar Jehan
Browse files

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.
parent 27dea4f7
Pipeline #322094 failed with stages
in 24 minutes and 19 seconds
......@@ -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)
{
......
......@@ -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;
}
......
......@@ -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)
{
......
......@@ -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",
......
......@@ -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)
{
......
......@@ -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);
......
......@@ -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)
{
......
......@@ -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)
{
......
......@@ -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,
......
......@@ -426,7 +426,6 @@ static GimpImage *