diff --git a/source/liblocate/source/liblocate.c b/source/liblocate/source/liblocate.c index 2e53d56..b98155c 100644 --- a/source/liblocate/source/liblocate.c +++ b/source/liblocate/source/liblocate.c @@ -207,11 +207,9 @@ void getBundlePath(char ** path, unsigned int * pathLength) } // Copy contents to caller, create caller ownership - *path = executablePath; - if (pathLength != 0x0) - { - *pathLength = bundlePathLength; - } + copyToStringOutParameter(executablePath, bundlePathLength, path, pathLength); + + free(executablePath); } void getModulePath(char ** path, unsigned int * pathLength) diff --git a/source/liblocate/source/utils.c b/source/liblocate/source/utils.c index d185c17..5664124 100644 --- a/source/liblocate/source/utils.c +++ b/source/liblocate/source/utils.c @@ -242,6 +242,11 @@ unsigned char fileExists(const char * path, unsigned int pathLength) { (void)pathLength; + if (path == 0) + { + return 0; + } + #ifdef SYSTEM_WINDOWS WIN32_FILE_ATTRIBUTE_DATA fileInfo; diff --git a/source/tests/liblocate-test/liblocate_test.cpp b/source/tests/liblocate-test/liblocate_test.cpp index bd60ed5..3e7433a 100644 --- a/source/tests/liblocate-test/liblocate_test.cpp +++ b/source/tests/liblocate-test/liblocate_test.cpp @@ -222,6 +222,8 @@ TEST_F(liblocate_test, libPrefix_Return) ASSERT_NE(nullptr, prefix); EXPECT_STREQ("lib", prefix); #endif + + free(prefix); } TEST_F(liblocate_test, libExtension_NoReturn) @@ -251,6 +253,8 @@ TEST_F(liblocate_test, libExtension_Return) ASSERT_NE(nullptr, extension); EXPECT_STREQ("so", extension); #endif + + free(extension); } TEST_F(liblocate_test, libExtensions_NoReturn) @@ -265,6 +269,7 @@ TEST_F(liblocate_test, libExtensions_Return) char ** extensions; unsigned int * lengths; unsigned int count; + unsigned int i; libExtensions(&extensions, &lengths, &count); @@ -290,6 +295,14 @@ TEST_F(liblocate_test, libExtensions_Return) ASSERT_NE(nullptr, extensions[0]); EXPECT_STREQ("so", extensions[0]); #endif + + for (i = 0; i < count; ++i) + { + free(extensions[i]); + } + + free(lengths); + free(extensions); } TEST_F(liblocate_test, homeDir) @@ -301,4 +314,6 @@ TEST_F(liblocate_test, homeDir) EXPECT_NE(nullptr, dir); EXPECT_LE(0, length); + + free(dir); }