diff --git a/build_helper.py b/build_helper.py index d76fc4b62a4aef380c60366b10caa139efce528a..c10b538dbb0f90da8d4acf536ddaf4e5da2b4556 100755 --- a/build_helper.py +++ b/build_helper.py @@ -66,6 +66,7 @@ def do_patch(patch_dir, target_dir): '0030-generate-flatbuffer-notice.patch', '0031-fix-matmul-assemble-can-not-protect-stack-in-mutil-thread.patch', '0032-fix-for-concat-bool-type.patch', + '0034-fix-nullptr-problems.patch', ] cwd = os.getcwd() diff --git a/patches/0034-fix-nullptr-problems.patch b/patches/0034-fix-nullptr-problems.patch new file mode 100644 index 0000000000000000000000000000000000000000..baf9568ac8595553261ba21fb75165f38f6af015 --- /dev/null +++ b/patches/0034-fix-nullptr-problems.patch @@ -0,0 +1,99 @@ +From 0947a3d466b9a6c9dd0c79ed79b94c6e51c30035 Mon Sep 17 00:00:00 2001 +From: wangqianggang <2593994958@qq.com> +Date: Wed, 21 Aug 2024 11:24:05 +0800 +Subject: [PATCH] fix nullptr problems + +--- + mindspore/lite/mindir/src/mindir_tensor.cc | 2 +- + mindspore/lite/src/litert/c_api/model_c.cc | 8 ++++++++ + mindspore/lite/src/litert/cache_session.cc | 4 ++++ + mindspore/lite/src/litert/lite_mindrt.cc | 4 ++++ + mindspore/lite/src/litert/pack_weight_manager.cc | 3 +++ + 5 files changed, 20 insertions(+), 1 deletion(-) + +diff --git a/mindspore/lite/mindir/src/mindir_tensor.cc b/mindspore/lite/mindir/src/mindir_tensor.cc +index 0e6a631e..cf81c8e6 100644 +--- a/mindspore/lite/mindir/src/mindir_tensor.cc ++++ b/mindspore/lite/mindir/src/mindir_tensor.cc +@@ -54,7 +54,7 @@ TensorPtr MindIR_Tensor_Create(const char *name, DataType data_type, const int32 + std::string MindIR_Tensor_GetName(ConstTensorPtr tensor) { + if (tensor != nullptr) { + auto value = static_cast(tensor); +- if (value != nullptr) { ++ if (value != nullptr && value->name() != nullptr) { + return value->name()->str(); + } else { + return ""; +diff --git a/mindspore/lite/src/litert/c_api/model_c.cc b/mindspore/lite/src/litert/c_api/model_c.cc +index 4f40b3d3..58d9ff9f 100644 +--- a/mindspore/lite/src/litert/c_api/model_c.cc ++++ b/mindspore/lite/src/litert/c_api/model_c.cc +@@ -385,6 +385,10 @@ char **OH_AI_TrainCfgGetLossName(OH_AI_TrainCfgHandle train_cfg, size_t *num) { + } + for (size_t i = 0; i < loss_name.size(); i++) { + name[i] = static_cast(malloc(loss_name[i].size() + 1)); ++ if (name[i] == nullptr) { ++ MS_LOG(ERROR) << "Failed to malloc name."; ++ return nullptr; ++ } + strcpy(name[i], loss_name[i].c_str()); + } + return name; +@@ -618,6 +622,10 @@ OH_AI_Status OH_AI_ExportModelBuffer(OH_AI_ModelHandle model, OH_AI_ModelType mo + export_inference_only, tensor_name); + auto data = static_cast(buffer.MutableData()); + *model_data = (char *) malloc(buffer.DataSize()); ++ if (*model_data == nullptr) { ++ MS_LOG(ERROR) << "*model_data is nullptr."; ++ return OH_AI_STATUS_LITE_NULLPTR; ++ } + *data_size = buffer.DataSize(); + memcpy(*model_data, data, buffer.DataSize()); + if (!ret.IsOk()) { +diff --git a/mindspore/lite/src/litert/cache_session.cc b/mindspore/lite/src/litert/cache_session.cc +index 7bafe3f7..e128c933 100644 +--- a/mindspore/lite/src/litert/cache_session.cc ++++ b/mindspore/lite/src/litert/cache_session.cc +@@ -209,6 +209,10 @@ int CacheSession::LoadModelAndCompileByPath(const std::string &model_path, minds + return RET_ERROR; + } else { + model = ImportInOutFromBuffer(model_buf, model_size, true, model_type, model_path); ++ if (model == nullptr) { ++ MS_LOG(ERROR) << "Import model failed"; ++ return RET_ERROR; ++ } + dynamic_cast(model)->PrepareInnerTensors(); + } + if (model == nullptr) { +diff --git a/mindspore/lite/src/litert/lite_mindrt.cc b/mindspore/lite/src/litert/lite_mindrt.cc +index fe7b64f2..4d1b4ba6 100644 +--- a/mindspore/lite/src/litert/lite_mindrt.cc ++++ b/mindspore/lite/src/litert/lite_mindrt.cc +@@ -106,6 +106,10 @@ int LiteOpActor::IsolateInputData(std::vector> *act + old_tensor->set_data_type(kernel_->desc().data_type); + } + SetTensorListTensorDataType(kernel_->desc().data_type, old_tensor); ++ if (kernel_->Context() == nullptr) { ++ MS_LOG(ERROR) << "kernel_->Context() is nullptr."; ++ return RET_NULL_PTR; ++ } + old_tensor->set_allocator(kernel_->Context()->allocator); + continue; + } +diff --git a/mindspore/lite/src/litert/pack_weight_manager.cc b/mindspore/lite/src/litert/pack_weight_manager.cc +index 09f4e4b4..554bf4dc 100644 +--- a/mindspore/lite/src/litert/pack_weight_manager.cc ++++ b/mindspore/lite/src/litert/pack_weight_manager.cc +@@ -264,6 +264,9 @@ void PackWeightManager::FreePackWeight(std::string runner_id, std::string model_ + MS_LOG(INFO) << "free pack weight of runner id: " << runner_id; + pack_weight_->FreePackWeight(runner_id); + } ++ } else { ++ MS_LOG(INFO) << "pack_weight_ is nullptr."; ++ return; + } + if (model_id.empty()) { + MS_LOG(INFO) << "model id is empty."; +-- +2.34.1 +