summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gmail.com>2023-01-06 12:33:08 +0000
committerEmmanuele Bassi <ebassi@gmail.com>2023-01-06 12:33:08 +0000
commit206cbf47a56eaca8a806000bb4370cc1c1759680 (patch)
treeb42d7e9e24ee8aea7185db4378663a2e0e13b393
parent73fa684e300355dd8e7febf9fcdb52ee6467d6e2 (diff)
parentdb2381026f9cedd7414973706eabe3c228964b1d (diff)
downloadglib-206cbf47a56eaca8a806000bb4370cc1c1759680.tar.gz
Merge branch '2871-find-program-for-path-leak' into 'main'
gutils: Avoid possible leaks in g_find_program_for_path() Closes #2871 See merge request GNOME/glib!3183
-rw-r--r--glib/gutils.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/glib/gutils.c b/glib/gutils.c
index d73b6474b..dce7cbee5 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -348,14 +348,18 @@ g_find_program_for_path (const char *program,
!g_file_test (program, G_FILE_TEST_IS_DIR))
{
gchar *out = NULL;
- char *cwd;
if (g_path_is_absolute (program))
- return g_strdup (program);
+ {
+ out = g_strdup (program);
+ }
+ else
+ {
+ char *cwd = g_get_current_dir ();
+ out = g_build_filename (cwd, program, NULL);
+ g_free (cwd);
+ }
- cwd = g_get_current_dir ();
- out = g_build_filename (cwd, program, NULL);
- g_free (cwd);
g_free (program_path);
return g_steal_pointer (&out);
@@ -499,6 +503,8 @@ g_find_program_for_path (const char *program,
ret = g_build_filename (cwd, startp, NULL);
g_free (cwd);
}
+
+ g_free (program_path);
g_free (startp_path);
g_free (freeme);
#ifdef G_OS_WIN32
@@ -510,7 +516,8 @@ g_find_program_for_path (const char *program,
g_free (startp_path);
}
while (*p++ != '\0');
-
+
+ g_free (program_path);
g_free (freeme);
#ifdef G_OS_WIN32
g_free ((gchar *) path_copy);