[gimp] plug-ins: use g_file_peek_path() instead of g_file_get_path().
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins: use g_file_peek_path() instead of g_file_get_path().
- Date: Fri, 1 Oct 2021 10:23:22 +0000 (UTC)
commit 545257226a20dc09cdc60c67744a5cded70d9b46
Author: Jehan <jehan girinstud io>
Date: Fri Oct 1 12:12:35 2021 +0200
plug-ins: use g_file_peek_path() instead of g_file_get_path().
Freeing the path immediately could lead to a free-after-use error as we
used it for an error message when the file pointer failed to be created,
as reported by Massimo (thanks again!).
Using g_file_peek_path() has also other advantages, such as being less
error-prone, but also possibly more efficient. First looking at the
implementation, for local files, we already have the path around, so no
additional memory allocation even needs to happen. As for the generic
code path, it would still allocate a new string, yet cache it and reuse
it when needed later. This makes the _peek_ call much better for quick
peek-use-discard usage.
plug-ins/file-dds/ddswrite.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
---
diff --git a/plug-ins/file-dds/ddswrite.c b/plug-ins/file-dds/ddswrite.c
index 177387305a..04df36aac6 100644
--- a/plug-ins/file-dds/ddswrite.c
+++ b/plug-ins/file-dds/ddswrite.c
@@ -512,12 +512,11 @@ write_dds (GFile *file,
GimpProcedure *procedure,
GObject *config)
{
- gchar *filename;
- FILE *fp;
- gint rc = 0;
- gint compression;
- gint mipmaps;
- gint savetype;
+ FILE *fp;
+ gint rc = 0;
+ gint compression;
+ gint mipmaps;
+ gint savetype;
g_object_get (config,
"compression-format", &compression,
@@ -569,13 +568,11 @@ write_dds (GFile *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)
{
- g_message ("Error opening %s", filename);
+ g_message ("Error opening %s", g_file_peek_path (file));
return GIMP_PDB_EXECUTION_ERROR;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]