summaryrefslogtreecommitdiffstats
path: root/libhb/ports.c
diff options
context:
space:
mode:
authorRodeo <[email protected]>2015-04-30 19:18:19 +0000
committerRodeo <[email protected]>2015-04-30 19:18:19 +0000
commite6fcf2f40c2628f7780d4841549f5d291024ae9f (patch)
treed6ae67bbc932baa945be6382c43fe2ae56791b8a /libhb/ports.c
parent29607855a2ce13dbd843b1d270b4e5bd0adeac35 (diff)
hb_get_user_config_directory: improvements.
Fix build with older MinGW-w64 toolchains. Fix potential memory leak and crashes. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7140 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/ports.c')
-rw-r--r--libhb/ports.c46
1 files changed, 38 insertions, 8 deletions
diff --git a/libhb/ports.c b/libhb/ports.c
index 6d43dc34f..e93fdb100 100644
--- a/libhb/ports.c
+++ b/libhb/ports.c
@@ -504,10 +504,37 @@ void hb_get_user_config_directory( char path[512] )
{
/* Create the base */
#if defined( SYS_CYGWIN ) || defined( SYS_MINGW )
+#ifndef CSIDL_FLAG_DONT_UNEXPAND
+ /*
+ * XXX: some old MinGW toolchains don't have SHGetKnownFolderPath.
+ *
+ * SHGetFolderPath is deprecated, but this should be no problem in practice.
+ *
+ * Note: explicitly call the Unicode/WCHAR function SHGetFolderPathW.
+ */
+ WCHAR wide_path[MAX_PATH];
+
+ if (SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, wide_path) == S_OK &&
+ WideCharToMultiByte(CP_UTF8, 0, wide_path, -1, path, 512, NULL, NULL) != 0)
+ {
+ path[511] = 0;
+ return;
+ }
+#else
WCHAR *wide_path;
- SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &wide_path);
- WideCharToMultiByte(CP_UTF8, 0, wide_path, -1, path, 512, NULL, NULL );
- path[511] = 0;
+
+ if (SHGetKnownFolderPath(&FOLDERID_RoamingAppData, 0, NULL, &wide_path) == S_OK &&
+ WideCharToMultiByte(CP_UTF8, 0, wide_path, -1, path, 512, NULL, NULL) != 0)
+ {
+ CoTaskMemFree(wide_path);
+ path[511] = 0;
+ return;
+ }
+ else if (wide_path != NULL)
+ {
+ CoTaskMemFree(wide_path);
+ }
+#endif // !defined CSIDL_FLAG_DONT_UNEXPAND
#elif defined( SYS_LINUX )
char *p;
@@ -515,6 +542,7 @@ void hb_get_user_config_directory( char path[512] )
{
strncpy(path, p, 511);
path[511] = 0;
+ return;
}
else if ((p = getenv("HOME")) != NULL)
{
@@ -523,15 +551,17 @@ void hb_get_user_config_directory( char path[512] )
int len = strlen(path);
strncpy(path + len, "/.config", 511 - len - 1);
path[511] = 0;
+ return;
}
- else
+#elif defined( __APPLE__ )
+ if (osx_get_user_config_directory(path) == 0)
{
- hb_error("Failed to lookup user config directory!");
- path[0] = 0;
+ return;
}
-#elif defined( __APPLE__ )
- osx_get_user_config_directory(path);
#endif
+
+ hb_error("Failed to lookup user config directory!");
+ path[0] = 0;
}
/************************************************************************