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.
This commit is contained in:
Jehan 2021-10-21 12:13:03 +02:00
parent 4dcbafc292
commit 99202c43a4
1 changed files with 8 additions and 4 deletions

View File

@ -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