[gimp] tools: win32_command() return value is never freed.
- From: Jehan <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] tools: win32_command() return value is never freed.
- Date: Thu, 21 Oct 2021 10:34:29 +0000 (UTC)
commit 99202c43a49316681a004cfa11b4f7774e54dbeb
Author: Jehan <jehan girinstud io>
Date: Thu Oct 21 12:13:03 2021 +0200
tools: win32_command() return value is never freed.
On Windows, the macros COPY, REMOVE and REMOVE_DIR are allocated
strings, unlike on other platforms, so the way we use these returned
values, they are never freed.
Instead make win32_command() keep a copy of the allocated string as
static to the function and free it there at each next call (the returned
value being type-casted to (const gchar *)). It will still leak the last
string, but anyway gimptool is short-lived.
Also it should silence static analyzers.
tools/gimptool.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/tools/gimptool.c b/tools/gimptool.c
index 5e51f45cf6..22fbd68148 100644
--- a/tools/gimptool.c
+++ b/tools/gimptool.c
@@ -101,15 +101,19 @@ static void usage (int exit_status) G_GNUC_NORETURN;
#ifdef G_OS_WIN32
-static gchar *
+static const gchar *
win32_command (const gchar *command)
{
- const gchar *comspec = getenv ("COMSPEC");
+ static gchar *cmd = NULL;
+ const gchar *comspec = getenv ("COMSPEC");
- if (!comspec)
+ if (comspec == NULL)
comspec = "cmd.exe";
- return g_strdup_printf ("%s /c %s", comspec, command);
+ g_free (cmd);
+ cmd = g_strdup_printf ("%s /c %s", comspec, command);
+
+ return (const gchar *) cmd;
}
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]