From: Woongsuk Cho Date: Mon, 26 Aug 2019 09:57:31 +0000 (+0900) Subject: fix bugs which found by coverity X-Git-Tag: accepted/tizen/unified/20190923.225320^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c28b17a9a487fb4c0ed433950d6a17cc71472ea9;p=platform%2Fcore%2Fdotnet%2Flauncher.git fix bugs which found by coverity --- diff --git a/NativeLauncher/util/path_manager.cc b/NativeLauncher/util/path_manager.cc index b207209..5df09ba 100644 --- a/NativeLauncher/util/path_manager.cc +++ b/NativeLauncher/util/path_manager.cc @@ -71,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); } diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc index c69b00b..e2cd5bd 100644 --- a/NativeLauncher/util/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -605,86 +605,90 @@ std::vector depsJsonParser(std::string rootPath, std::string execNa std::vector parserData; std::string depsJsonName = execName.substr(0, execName.rfind(".dll")) + ".deps.json"; std::string depsJsonPath = concatPath(rootPath, depsJsonName); - if (bf::exists(depsJsonPath)) { - std::ifstream ifs(depsJsonPath); - Json::CharReaderBuilder reader; - Json::Value root; - std::string error; - if (ifs.is_open()) { - if (!Json::parseFromStream(reader, ifs, &root, &error)) { - _ERR("Failed to parse of deps.json"); - ifs.close(); - tpaAssemblies.clear(); - return parserData; - } - const Json::Value runtimeTargetName = root["runtimeTarget"]["name"]; - const Json::Value nugetPackages = root["targets"][runtimeTargetName.asString().c_str()]; - std::vector appDependencies; - for (auto& nuget : nugetPackages.getMemberNames()) { - if (strstr(nuget.c_str(), (execName.substr(0, execName.find(".Tizen."))).c_str()) != NULL || - strstr(nuget.c_str(), (execName.substr(0, execName.find(".dll"))).c_str()) != NULL) { - const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"]; - if (assemblies != Json::nullValue) { - const Json::Value dependencies = nugetPackages[nuget.c_str()]["dependencies"]; - for (auto& dependency : dependencies.getMemberNames()) { - appDependencies.push_back(dependency); - } - } + try { + if (bf::exists(depsJsonPath)) { + std::ifstream ifs(depsJsonPath); + Json::CharReaderBuilder reader; + Json::Value root; + std::string error; + if (ifs.is_open()) { + if (!Json::parseFromStream(reader, ifs, &root, &error)) { + _ERR("Failed to parse of deps.json"); + ifs.close(); + tpaAssemblies.clear(); + return parserData; } - } - for (auto& nuget : nugetPackages.getMemberNames()) { - //Skip the nuget package related to Tizen - if (strstr(nuget.c_str(), TIZEN_DOTNET_NUGET) == NULL && - strstr(nuget.c_str(), TIZEN_DOTNET_SDK_NUGET) == NULL && - strstr(nuget.c_str(), (execName.substr(0, execName.find(".Tizen."))).c_str()) == NULL && - strstr(nuget.c_str(), (execName.substr(0, execName.find(".dll"))).c_str()) == NULL) { - const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"]; - if (assemblies != Json::nullValue) { - const Json::Value dependencies = nugetPackages[nuget.c_str()]["dependencies"]; - bool hasDependency = false; - for (auto& dependency : dependencies.getMemberNames()) { - //Skip the nugget package that is dependent on another nuget package - if (strstr(dependency.c_str(), TIZEN_DOTNET_NUGET) == NULL && - strstr(dependency.c_str(), NET_STANDARD_LIBRARY_NUGET) == NULL) { - hasDependency = true; - for (auto& ad : appDependencies) { - if (!strcmp(ad.c_str(), dependency.c_str())) { - hasDependency = true; - break; - } else { - hasDependency = false; - } - } - if (hasDependency) break; + const Json::Value runtimeTargetName = root["runtimeTarget"]["name"]; + const Json::Value nugetPackages = root["targets"][runtimeTargetName.asString().c_str()]; + std::vector appDependencies; + for (auto& nuget : nugetPackages.getMemberNames()) { + if (strstr(nuget.c_str(), (execName.substr(0, execName.find(".Tizen."))).c_str()) != NULL || + strstr(nuget.c_str(), (execName.substr(0, execName.find(".dll"))).c_str()) != NULL) { + const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"]; + if (assemblies != Json::nullValue) { + const Json::Value dependencies = nugetPackages[nuget.c_str()]["dependencies"]; + for (auto& dependency : dependencies.getMemberNames()) { + appDependencies.push_back(dependency); } } - if (!hasDependency) { - bool isExistTpaAssembly = false; - for (auto& assembly : assemblies.getMemberNames()) { - std::string assemblyName = assembly.substr(assembly.rfind('/') + 1); - //Skip the assembly present in the TPA list - for (auto& tpa : tpaAssemblies) { - if (!strcmp(replaceAll(tpa, ".ni.dll", ".dll").c_str(), assembly.c_str())) { - isExistTpaAssembly = true; - break; + } + } + for (auto& nuget : nugetPackages.getMemberNames()) { + //Skip the nuget package related to Tizen + if (strstr(nuget.c_str(), TIZEN_DOTNET_NUGET) == NULL && + strstr(nuget.c_str(), TIZEN_DOTNET_SDK_NUGET) == NULL && + strstr(nuget.c_str(), (execName.substr(0, execName.find(".Tizen."))).c_str()) == NULL && + strstr(nuget.c_str(), (execName.substr(0, execName.find(".dll"))).c_str()) == NULL) { + const Json::Value assemblies = nugetPackages[nuget.c_str()]["runtime"]; + if (assemblies != Json::nullValue) { + const Json::Value dependencies = nugetPackages[nuget.c_str()]["dependencies"]; + bool hasDependency = false; + for (auto& dependency : dependencies.getMemberNames()) { + //Skip the nugget package that is dependent on another nuget package + if (strstr(dependency.c_str(), TIZEN_DOTNET_NUGET) == NULL && + strstr(dependency.c_str(), NET_STANDARD_LIBRARY_NUGET) == NULL) { + hasDependency = true; + for (auto& ad : appDependencies) { + if (!strcmp(ad.c_str(), dependency.c_str())) { + hasDependency = true; + break; + } else { + hasDependency = false; + } } + if (hasDependency) break; } - if (isExistTpaAssembly) break; } - if (!isExistTpaAssembly) { + if (!hasDependency) { + bool isExistTpaAssembly = false; for (auto& assembly : assemblies.getMemberNames()) { std::string assemblyName = assembly.substr(assembly.rfind('/') + 1); - parserData.push_back(nuget + ":" + assemblyName); - _INFO("Nuget : [%s] / Assembly : [%s]", nuget.c_str(), assemblyName.c_str()); + //Skip the assembly present in the TPA list + for (auto& tpa : tpaAssemblies) { + if (!strcmp(replaceAll(tpa, ".ni.dll", ".dll").c_str(), assembly.c_str())) { + isExistTpaAssembly = true; + break; + } + } + if (isExistTpaAssembly) break; + } + if (!isExistTpaAssembly) { + for (auto& assembly : assemblies.getMemberNames()) { + std::string assemblyName = assembly.substr(assembly.rfind('/') + 1); + parserData.push_back(nuget + ":" + assemblyName); + _INFO("Nuget : [%s] / Assembly : [%s]", nuget.c_str(), assemblyName.c_str()); + } } } } } } + appDependencies.clear(); + ifs.close(); } - appDependencies.clear(); - ifs.close(); } + } catch (const Json::LogicError& error) { + _ERR("Failed to parse Json: %s", error.what()); } tpaAssemblies.clear(); return parserData;