From cc5578fbd73ac3845daaa098601640a41cc8586a Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 27 Jan 2011 21:57:57 -0500 Subject: [PATCH] Make load_user_special_dirs() resistant to nonexistent dirs --- glib/gutils.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/glib/gutils.c b/glib/gutils.c index 5512fd480..4288bc66a 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -2427,10 +2427,15 @@ load_user_special_dirs (void) { wcp = NULL; (*p_SHGetKnownFolderPath) (&FOLDERID_Downloads, 0, NULL, &wcp); - g_user_special_dirs[G_USER_DIRECTORY_DOWNLOAD] = g_utf16_to_utf8 (wcp, -1, NULL, NULL, NULL); - if (g_user_special_dirs[G_USER_DIRECTORY_DOWNLOAD] == NULL) - g_user_special_dirs[G_USER_DIRECTORY_DOWNLOAD] = get_special_folder (CSIDL_DESKTOPDIRECTORY); - CoTaskMemFree (wcp); + if (wcp) + { + g_user_special_dirs[G_USER_DIRECTORY_DOWNLOAD] = g_utf16_to_utf8 (wcp, -1, NULL, NULL, NULL); + if (g_user_special_dirs[G_USER_DIRECTORY_DOWNLOAD] == NULL) + g_user_special_dirs[G_USER_DIRECTORY_DOWNLOAD] = get_special_folder (CSIDL_DESKTOPDIRECTORY); + CoTaskMemFree (wcp); + } + else + g_user_special_dirs[G_USER_DIRECTORY_DOWNLOAD] = get_special_folder (CSIDL_DESKTOPDIRECTORY); } g_user_special_dirs[G_USER_DIRECTORY_MUSIC] = get_special_folder (CSIDL_MYMUSIC); @@ -2445,10 +2450,15 @@ load_user_special_dirs (void) { wcp = NULL; (*p_SHGetKnownFolderPath) (&FOLDERID_Public, 0, NULL, &wcp); - g_user_special_dirs[G_USER_DIRECTORY_PUBLIC_SHARE] = g_utf16_to_utf8 (wcp, -1, NULL, NULL, NULL); - if (g_user_special_dirs[G_USER_DIRECTORY_PUBLIC_SHARE] == NULL) - g_user_special_dirs[G_USER_DIRECTORY_PUBLIC_SHARE] = get_special_folder (CSIDL_COMMON_DOCUMENTS); - CoTaskMemFree (wcp); + if (wcp) + { + g_user_special_dirs[G_USER_DIRECTORY_PUBLIC_SHARE] = g_utf16_to_utf8 (wcp, -1, NULL, NULL, NULL); + if (g_user_special_dirs[G_USER_DIRECTORY_PUBLIC_SHARE] == NULL) + g_user_special_dirs[G_USER_DIRECTORY_PUBLIC_SHARE] = get_special_folder (CSIDL_COMMON_DOCUMENTS); + CoTaskMemFree (wcp); + } + else + g_user_special_dirs[G_USER_DIRECTORY_PUBLIC_SHARE] = get_special_folder (CSIDL_COMMON_DOCUMENTS); } g_user_special_dirs[G_USER_DIRECTORY_TEMPLATES] = get_special_folder (CSIDL_TEMPLATES);