From 36e4c11a2ac8e1a2310d948b6f039d28be4cf521 Mon Sep 17 00:00:00 2001 From: Tim Mayberry Date: Tue, 18 Aug 2015 14:04:21 +1000 Subject: [PATCH] Add utility function to get windows packaging directory to avoid memory leaks There were a few other small leaks in pbd and evoral test code but I didn't bother changing them. Perhaps this function would be better off in PBD:: so it can be used everywhere. --- libs/ardour/ardour/filesystem_paths.h | 7 +++++++ libs/ardour/filesystem_paths.cc | 21 +++++++++++++++++++-- libs/ardour/plugin_manager.cc | 2 +- libs/ardour/test/test_util.cc | 3 ++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/libs/ardour/ardour/filesystem_paths.h b/libs/ardour/ardour/filesystem_paths.h index afa66453eb..cc1a21c45e 100644 --- a/libs/ardour/ardour/filesystem_paths.h +++ b/libs/ardour/ardour/filesystem_paths.h @@ -78,6 +78,13 @@ namespace ARDOUR { * @return our 'Windows' search path ( corresponds to /share/ardour3 ) */ LIBARDOUR_API PBD::Searchpath windows_search_path (); + + /** + * @return Convenience function that calls + * g_win32_get_package_installation_directory_of_module but returns a + * std::string + */ + LIBARDOUR_API std::string windows_package_directory_path (); #endif } // namespace ARDOUR diff --git a/libs/ardour/filesystem_paths.cc b/libs/ardour/filesystem_paths.cc index fe1afd85d8..7e9b4e1857 100644 --- a/libs/ardour/filesystem_paths.cc +++ b/libs/ardour/filesystem_paths.cc @@ -200,7 +200,7 @@ std::string ardour_dll_directory () { #ifdef PLATFORM_WINDOWS - std::string dll_dir_path(g_win32_get_package_installation_directory_of_module(NULL)); + std::string dll_dir_path(windows_package_directory_path()); dll_dir_path = Glib::build_filename (dll_dir_path, "lib"); return Glib::build_filename (dll_dir_path, LIBARDOUR); #else @@ -217,10 +217,27 @@ ardour_dll_directory () Searchpath windows_search_path () { - std::string dll_dir_path(g_win32_get_package_installation_directory_of_module(NULL)); + std::string dll_dir_path(windows_package_directory_path()); dll_dir_path = Glib::build_filename (dll_dir_path, "share"); return Glib::build_filename (dll_dir_path, LIBARDOUR); } + +std::string +windows_package_directory_path () +{ + char* package_dir = + g_win32_get_package_installation_directory_of_module (NULL); + + if (package_dir == NULL) { + fatal << string_compose (_("Cannot determine %1 package directory"), + PROGRAM_NAME) << endmsg; + // not reached + } + + std::string package_dir_path(package_dir); + g_free(package_dir); + return package_dir_path; +} #endif Searchpath diff --git a/libs/ardour/plugin_manager.cc b/libs/ardour/plugin_manager.cc index 4eb67db48d..7a14154d3c 100644 --- a/libs/ardour/plugin_manager.cc +++ b/libs/ardour/plugin_manager.cc @@ -123,7 +123,7 @@ PluginManager::PluginManager () #ifdef PLATFORM_WINDOWS // on windows the .exe needs to be in the same folder with libardour.dll - vstsp += Glib::build_filename(g_win32_get_package_installation_directory_of_module (0), "bin"); + vstsp += Glib::build_filename(windows_package_directory_path(), "bin"); #else // on Unices additional internal-use binaries are deployed to $libdir vstsp += ARDOUR::ardour_dll_directory(); diff --git a/libs/ardour/test/test_util.cc b/libs/ardour/test/test_util.cc index 3e9566c0e4..f717290ce9 100644 --- a/libs/ardour/test/test_util.cc +++ b/libs/ardour/test/test_util.cc @@ -27,6 +27,7 @@ #include "ardour/session.h" #include "ardour/audioengine.h" +#include "ardour/filesystem_paths.h" #include "test_util.h" @@ -133,7 +134,7 @@ PBD::Searchpath test_search_path () { #ifdef PLATFORM_WINDOWS - std::string wsp(g_win32_get_package_installation_directory_of_module(NULL)); + std::string wsp(windows_package_directory_path()); return Glib::build_filename (wsp, "ardour_testdata"); #else return Glib::getenv("ARDOUR_TEST_PATH"); -- 2.30.2