Add utility function to get windows packaging directory to avoid memory leaks
authorTim Mayberry <mojofunk@gmail.com>
Tue, 18 Aug 2015 04:04:21 +0000 (14:04 +1000)
committerTim Mayberry <mojofunk@gmail.com>
Tue, 18 Aug 2015 05:10:55 +0000 (15:10 +1000)
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
libs/ardour/filesystem_paths.cc
libs/ardour/plugin_manager.cc
libs/ardour/test/test_util.cc

index afa66453eb2a18aafc100fb12292bfd132806693..cc1a21c45efbbeaf81903da384d459b1a350695d 100644 (file)
@@ -78,6 +78,13 @@ namespace ARDOUR {
         * @return our 'Windows' search path ( corresponds to <install_dir>/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
 
index fe1afd85d82b1a73e5fc1b11346d3e7857930b20..7e9b4e18577f263e1b9b7c11400834fc3cee0863 100644 (file)
@@ -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
index 4eb67db48dd044450e15d98b5b5a52d3b2159f01..7a14154d3c2e449712b12c09f8e696b82a5724e4 100644 (file)
@@ -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();
index 3e9566c0e408ba2f7d633b4d90ca54050102b775..f717290ce9c65aa1bf27bf51e1993bed5d23dfe9 100644 (file)
@@ -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");