From 964c3f10699f000dba996ce13d04de7f28b63e41 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Fri, 19 Sep 2025 13:29:07 +0100 Subject: [PATCH] gutils: Move the special case default value for G_USER_DIRECTORY_DESKTOP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise it isn’t set on every code path, and it’s possible for a caller to receive `NULL` when they call `g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP)`, i.e. after calling `g_reload_user_special_dirs_cache()`. Signed-off-by: Philip Withnall --- glib/gutils.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/glib/gutils.c b/glib/gutils.c index 4d19ddb61..02da41b68 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -2279,21 +2279,20 @@ load_user_special_dirs_unlocked (void) const gchar *config_dir = NULL; const gchar *home_dir; gchar *config_file; - gchar *data; + char *data = NULL; config_dir = g_get_user_config_dir_unlocked (); config_file = g_build_filename (config_dir, "user-dirs.dirs", NULL); - - if (!g_file_get_contents (config_file, &data, NULL, NULL)) - { - g_free (config_file); - return; - } - home_dir = g_get_home_dir_unlocked (); - load_user_special_dirs_from_string (data, home_dir, g_user_special_dirs); + + if (g_file_get_contents (config_file, &data, NULL, NULL)) + load_user_special_dirs_from_string (data, home_dir, g_user_special_dirs); + + /* Special-case desktop for historical compatibility */ + if (g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] == NULL) + g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] = g_build_filename (home_dir, "Desktop", NULL); g_free (data); g_free (config_file); @@ -2392,16 +2391,7 @@ g_get_user_special_dir (GUserDirectory directory) if (G_UNLIKELY (g_user_special_dirs == NULL)) { g_user_special_dirs = g_new0 (gchar *, G_USER_N_DIRECTORIES); - load_user_special_dirs_unlocked (); - - /* Special-case desktop for historical compatibility */ - if (g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] == NULL) - { - gchar *home_dir = g_build_home_dir (); - g_user_special_dirs[G_USER_DIRECTORY_DESKTOP] = g_build_filename (home_dir, "Desktop", NULL); - g_free (home_dir); - } } user_special_dir = g_user_special_dirs[directory];