diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 8b3c82831f..e717b5946f 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -121,6 +121,9 @@ public: std::shared_ptr runtimeExtractor; if (runtimeExtractorMap_.find(hapPath) == runtimeExtractorMap_.end()) { runtimeExtractor = RuntimeExtractor::Create(hapPath); + if (runtimeExtractor == nullptr) { + return result; + } runtimeExtractor->SetRuntimeFlag(true); runtimeExtractorMap_.insert(make_pair(hapPath, runtimeExtractor)); } else { @@ -261,6 +264,9 @@ private: bundleName_ = options.bundleName; panda::JSNApi::SetHostResolvePathTracker(vm_, JsModuleSearcher(options.bundleName)); std::shared_ptr runtimeExtractor = RuntimeExtractor::Create(options.hapPath); + if (runtimeExtractor == nullptr) { + return false; + } runtimeExtractor->SetRuntimeFlag(true); runtimeExtractorMap_.insert(make_pair(options.hapPath, runtimeExtractor)); panda::JSNApi::SetHostResolveBufferTracker( @@ -615,6 +621,9 @@ bool JsRuntime::RunScript(const std::string& srcPath, const std::string& hapPath std::shared_ptr runtimeExtractor; if (runtimeExtractorMap_.find(hapPath) == runtimeExtractorMap_.end()) { runtimeExtractor = RuntimeExtractor::Create(hapPath); + if (runtimeExtractor == nullptr) { + return result; + } runtimeExtractor->SetRuntimeFlag(true); runtimeExtractorMap_.insert(make_pair(hapPath, runtimeExtractor)); } else { diff --git a/frameworks/native/runtime/utils/src/runtime_extractor.cpp b/frameworks/native/runtime/utils/src/runtime_extractor.cpp index 828a2499a3..833fd911b5 100644 --- a/frameworks/native/runtime/utils/src/runtime_extractor.cpp +++ b/frameworks/native/runtime/utils/src/runtime_extractor.cpp @@ -49,7 +49,7 @@ std::shared_ptr RuntimeExtractor::Create(const std::string& ha { if (hapPath.empty()) { HILOG_ERROR("source is nullptr"); - return std::shared_ptr(); + return nullptr; } std::string loadPath; @@ -61,7 +61,7 @@ std::shared_ptr RuntimeExtractor::Create(const std::string& ha std::shared_ptr runtimeExtractor = std::make_shared(loadPath); if (!runtimeExtractor->Init()) { HILOG_ERROR("RuntimeExtractor create failed"); - return std::shared_ptr(); + return nullptr; } return runtimeExtractor;