diff --git a/mindspore/lite/tools/converter/legacy_optimizer/graph/infershape_pass.cc b/mindspore/lite/tools/converter/legacy_optimizer/graph/infershape_pass.cc index b5d6d1acdef..b6f579b347e 100644 --- a/mindspore/lite/tools/converter/legacy_optimizer/graph/infershape_pass.cc +++ b/mindspore/lite/tools/converter/legacy_optimizer/graph/infershape_pass.cc @@ -40,7 +40,9 @@ void FreeTensors(std::vector *input_tensors, std::vector *ou return; } for (auto &tensor : *input_tensors) { - tensor->set_data(nullptr); + if (tensor->data_type() != kObjectTypeString && tensor->data_type() != kObjectTypeTensorType) { + tensor->set_data(nullptr); + } delete tensor; tensor = nullptr; } @@ -48,7 +50,9 @@ void FreeTensors(std::vector *input_tensors, std::vector *ou return; } for (auto &tensor : *output_tensors) { - tensor->set_data(nullptr); + if (tensor->data_type() != kObjectTypeString && tensor->data_type() != kObjectTypeTensorType) { + tensor->set_data(nullptr); + } delete tensor; tensor = nullptr; } @@ -130,12 +134,6 @@ void ConvertOtherTensor(MetaGraphT *graph, uint32_t index, bool *convert_succ, s lite_tensors->emplace_back(lite_tensor.release()); return; } - auto ret = lite_tensor->MallocData(); - if (ret != RET_OK) { - MS_LOG(ERROR) << "Malloc tensor data failed"; - *convert_succ = false; - return; - } if (lite_tensor->root_tensor() != nullptr) { lite_tensor->root_tensor()->set_data(tensorT->data.data()); } else { diff --git a/mindspore/lite/tools/optimizer/fusion/conv_transform_fusion.cc b/mindspore/lite/tools/optimizer/fusion/conv_transform_fusion.cc index d3716d15093..0d8fc7e40d4 100644 --- a/mindspore/lite/tools/optimizer/fusion/conv_transform_fusion.cc +++ b/mindspore/lite/tools/optimizer/fusion/conv_transform_fusion.cc @@ -209,6 +209,7 @@ void ConvTransformFusion::GenNewConvTensor(const FuncGraphPtr &func_graph, const CalNewBiasTensor(bias_data, kernel_num, bias_flag, trans_scale, trans_bias); if (!bias_flag) { auto bias_node = AddNewBiasNode(bias_data, func_graph, kernel_num, weight_tensor); + delete[] bias_data; bias_node->set_name(conv_node->fullname_with_scope() + "_bias"); conv_node->add_input(bias_node); } diff --git a/mindspore/lite/tools/optimizer/graph/node_infershape.cc b/mindspore/lite/tools/optimizer/graph/node_infershape.cc index decbdbc54d6..794c0a0ac4a 100644 --- a/mindspore/lite/tools/optimizer/graph/node_infershape.cc +++ b/mindspore/lite/tools/optimizer/graph/node_infershape.cc @@ -452,7 +452,7 @@ STATUS NodeInferShape::ConvertToLiteTensor(const std::vector &da return RET_ERROR; } } else { - auto tensor_data = new (std::nothrow) char[tensor_size]; + auto tensor_data = reinterpret_cast(malloc(tensor_size)); if (tensor_data == nullptr) { MS_LOG(ERROR) << "tensor_data is nullptr"; delete tensor; @@ -460,7 +460,7 @@ STATUS NodeInferShape::ConvertToLiteTensor(const std::vector &da } if (memcpy_s(tensor_data, tensor_size, data_info.data_.data(), tensor_size) != EOK) { delete tensor; - delete[](tensor_data); + free(tensor_data); MS_LOG(ERROR) << "memcpy error: "; return lite::RET_ERROR; }