From 5c40eea518faefde55041509ba3dd4b1252b1925 Mon Sep 17 00:00:00 2001 From: Stefan Gehn Date: Sat, 12 Jul 2014 22:03:16 +0200 Subject: [PATCH] Fix inconsistent path generation and checks on win32 - Always check the return value of g_win32_get_package_installation_directory_of_module, this call may fail and return NULL - g_build_filename is documented as never returning NULL, no need to check for that --- server/main.c | 18 +++++++++--------- server/plugins.c | 6 +----- src/gui.c | 7 +------ 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/server/main.c b/server/main.c index 6b4ba1f..fbb9252 100644 --- a/server/main.c +++ b/server/main.c @@ -788,10 +788,13 @@ read_config(void) // on windows also load config from INSTALLDIR/etc/gkrellmd.conf #if defined(WIN32) install_path = g_win32_get_package_installation_directory_of_module(NULL); - path = g_build_filename(install_path, "etc", GKRELLMD_CONFIG, NULL); - load_config(path); - g_free(install_path); - g_free(path); + if (install_path != NULL) + { + path = g_build_filename(install_path, "etc", GKRELLMD_CONFIG, NULL); + load_config(path); + g_free(path); + g_free(install_path); + } #endif _GK.homedir = (gchar *) g_get_home_dir(); @@ -1655,11 +1658,8 @@ int main(int argc, char* argv[]) if (install_path != NULL) { locale_dir = g_build_filename(install_path, LOCALEDIR, NULL); - if (locale_dir != NULL) - { - bindtextdomain(PACKAGE_D, locale_dir); - g_free(locale_dir); - } + bindtextdomain(PACKAGE_D, locale_dir); + g_free(locale_dir); g_free(install_path); } #else diff --git a/server/plugins.c b/server/plugins.c index 092d544..ae2263c 100644 --- a/server/plugins.c +++ b/server/plugins.c @@ -284,18 +284,14 @@ gkrellmd_plugins_load(void) g_free(path); #if defined(WIN32) - path = NULL; gchar *install_path; install_path = g_win32_get_package_installation_directory_of_module(NULL); if (install_path != NULL) { path = g_build_filename(install_path, "lib", "gkrellm2", "plugins-gkrellmd", NULL); - g_free(install_path); - } - if (path) - { gkrellmd_plugin_scan(path); g_free(path); + g_free(install_path); } #endif diff --git a/src/gui.c b/src/gui.c index d80591c..2dbbb13 100644 --- a/src/gui.c +++ b/src/gui.c @@ -1426,19 +1426,14 @@ gkrellm_make_themes_list(void) add_themes_to_list(theme_dir, TRUE); #if defined(WIN32) - theme_dir = NULL; gchar *install_path; install_path = g_win32_get_package_installation_directory_of_module(NULL); if (install_path != NULL) { theme_dir = g_build_filename(install_path, "share", "gkrellm2", "themes", NULL); - g_free(install_path); - } - if (theme_dir) - { add_themes_to_list(theme_dir, FALSE); g_free(theme_dir); - theme_dir = NULL; + g_free(install_path); } #endif