diff --git a/mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc b/mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc index 539c48ec47..b497f9c47f 100644 --- a/mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/base/crop_base.cc @@ -38,11 +38,11 @@ int CropBaseCPUKernel::ReSize() { if (crop_para_->in_shape_ == nullptr) { MS_LOG(ERROR) << "in_shape_ is nullptr"; return RET_ERROR; - } else { - memcpy(reinterpret_cast(const_cast(crop_para_->in_shape_)), input_shape.data(), - sizeof(int) * input_dim); } + memcpy(reinterpret_cast(const_cast(crop_para_->in_shape_)), input_shape.data(), + sizeof(int) * input_dim); + auto *out_tensor = out_tensors_.at(kOutputIndex); auto output_shape = out_tensor->shape(); size_t output_dim = output_shape.size(); @@ -51,10 +51,11 @@ int CropBaseCPUKernel::ReSize() { if (crop_para_->out_shape_ == nullptr) { MS_LOG(ERROR) << "out_shape_ is nullptr"; return RET_ERROR; - } else { - memcpy(reinterpret_cast(const_cast(crop_para_->out_shape_)), output_shape.data(), - sizeof(int) * output_dim); } + + memcpy(reinterpret_cast(const_cast(crop_para_->out_shape_)), output_shape.data(), + sizeof(int) * output_dim); + MS_ASSERT(input_dim <= CROP_OFFSET_MAX_SIZE); crop_para_->input_dim_ = input_dim; PadOffset(input_dim, crop_para_); diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc index c594e01b65..5a9ceae6a8 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/add_int8.cc @@ -101,9 +101,14 @@ int QuantizedAddCPUKernel::Run() { if (in_tensors_.at(0)->ElementsNum() != in_tensors_.at(1)->ElementsNum()) { input0_data_ = static_cast(ctx_->allocator->Malloc(out_tensors_.at(0)->Size())); + if (input0_data_ == nullptr) { + MS_LOG(ERROR) << "malloc input0_data_ failed."; + return RET_ERROR; + } input1_data_ = static_cast(ctx_->allocator->Malloc(out_tensors_.at(0)->Size())); - if (!input0_data_ || !input1_data_) { - MS_LOG(ERROR) << "malloc input0_data_ || input1_data_ failed."; + if (input1_data_ == nullptr) { + MS_LOG(ERROR) << "malloc input1_data_ failed."; + ctx_->allocator->Free(input0_data_); return RET_ERROR; } diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc index 3ac7e3f93f..646a2a27c3 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/bias_add_int8.cc @@ -51,9 +51,14 @@ int BiasAddInt8CPUKernel::Run() { auto out = reinterpret_cast(out_tensors_.at(0)->MutableData()); size_t data_size = in_tensors_.at(0)->ElementsNum(); auto tile_in = static_cast(ctx_->allocator->Malloc(data_size)); + if (tile_in == nullptr) { + MS_LOG(ERROR) << "Failed to malloc momery"; + return NNACL_ERR; + } auto tile_bias = static_cast(ctx_->allocator->Malloc(data_size)); - if (tile_in == nullptr || tile_bias == nullptr) { + if (tile_bias == nullptr) { MS_LOG(ERROR) << "Failed to malloc momery"; + ctx_->allocator->Free(tile_in); return NNACL_ERR; } BroadcastAddInt8(in, bias, tile_in, tile_bias, out, data_size, diff --git a/mindspore/lite/src/runtime/kernel/arm/int8/sub_int8.cc b/mindspore/lite/src/runtime/kernel/arm/int8/sub_int8.cc index fd260d36de..df85cd40ba 100644 --- a/mindspore/lite/src/runtime/kernel/arm/int8/sub_int8.cc +++ b/mindspore/lite/src/runtime/kernel/arm/int8/sub_int8.cc @@ -132,11 +132,14 @@ int SubInt8CPUKernel::Run() { tile_para.out_shape_[i] = out_tensors_.at(0)->DimensionSize(i); } tile0_data_ = static_cast(context_->allocator->Malloc(out_tensors_.at(0)->Size())); + if (tile0_data_ == nullptr) { + MS_LOG(ERROR) << "malloc memroy fail!"; + return RET_ERROR; + } tile1_data_ = static_cast(context_->allocator->Malloc(out_tensors_.at(0)->Size())); - if (tile0_data_ == nullptr || tile1_data_ == nullptr) { + if (tile1_data_ == nullptr) { MS_LOG(ERROR) << "malloc memroy fail!"; context_->allocator->Free(tile0_data_); - context_->allocator->Free(tile1_data_); return RET_ERROR; } TileDimensionsUint8(static_cast(in_tensors_.at(0)->MutableData()), diff --git a/mindspore/lite/src/sub_graph_kernel.cc b/mindspore/lite/src/sub_graph_kernel.cc index 24a35f0fe6..16b2959810 100644 --- a/mindspore/lite/src/sub_graph_kernel.cc +++ b/mindspore/lite/src/sub_graph_kernel.cc @@ -194,7 +194,7 @@ int CpuFp16SubGraph::PostProcess() { tensor->set_data(nullptr); tensor->set_data_type(TypeId::kNumberTypeFloat32); auto ret = tensor->MallocData(); - if (RET_OK != ret) { + if (ret != RET_OK) { MS_LOG(ERROR) << "malloc data failed"; if (this->context_ != nullptr && this->context_->allocator != nullptr) { this->context_->allocator->Free(float16_data);