fix bugs which found by coverity
[platform/core/dotnet/launcher.git] / NativeLauncher / util / path_manager.cc
index daa8f34..5df09ba 100644 (file)
@@ -25,7 +25,6 @@
 #include "log.h"
 
 static const char* __TIZEN_API_PATH_KEY = "db/dotnet/tizen_api_path";
-static const char* PLATFORM_TPA_CACHE = "/usr/share/dotnet.tizen/lib/platform_tpa_cache";
 
 #define __XSTR(x) #x
 #define __STR(x) __XSTR(x)
@@ -43,10 +42,16 @@ typedef struct DllPath {
 
 static DllPath* __dllPath = nullptr;
 static std::string __tpa;
+bool initializedPathManager = false;
 
 // on success, return 0. otherwise return -1.
 int initializePathManager(const std::string& runtimeDir, const std::string& tizenFXDir, const std::string& extraDir)
 {
+       if (initializedPathManager) {
+               _INFO("Path manager already initialized");
+               return 0;
+       }
+
        __dllPath = new DllPath();
        if (!__dllPath) {
                _ERR("fail to allocate memory for dll path structure\n");
@@ -66,6 +71,7 @@ int initializePathManager(const std::string& runtimeDir, const std::string& tize
                if (tmp) {
                        __dllPath->tizenfx_dir = std::string(tmp);
                        _DBG("Device API Directory is set by vconf : %s", tmp);
+                       free(tmp);
                } else {
                        __dllPath->tizenfx_dir = absolutePath(__DEVICE_API_DIR);
                }
@@ -85,6 +91,7 @@ int initializePathManager(const std::string& runtimeDir, const std::string& tize
 
        _INFO("Path manager initialize success");
 
+       initializedPathManager = true;
        return 0;
 }
 
@@ -94,6 +101,8 @@ void finalizePathManager()
                delete __dllPath;
                __dllPath = NULL;
        }
+
+       initializedPathManager = false;
 }
 
 std::string getRuntimeDir()
@@ -121,7 +130,7 @@ static std::string getPlatformTPA()
        std::string platform_tpa;
 
        if (isFileExist(PLATFORM_TPA_CACHE)) {
-               _INFO("platform tpa cache found.\n");
+               _INFO("platform tpa cache found.");
                std::ifstream cacheFile;
                cacheFile.open(PLATFORM_TPA_CACHE);
                std::getline(cacheFile, platform_tpa);