From 8b3c8561ced538c6c2070f5bbe98dd3cd5755522 Mon Sep 17 00:00:00 2001 From: Yufeng Li Date: Sun, 5 May 2019 21:46:00 -0700 Subject: [PATCH] Avoid to call memory allocation if tensor size is 0 (#972) --- onnxruntime/core/framework/tensor.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/framework/tensor.cc b/onnxruntime/core/framework/tensor.cc index 4463ec7145..d0085c0fe6 100644 --- a/onnxruntime/core/framework/tensor.cc +++ b/onnxruntime/core/framework/tensor.cc @@ -21,7 +21,9 @@ Tensor::Tensor(MLDataType p_type, const TensorShape& shape, std::shared_ptr(shape_size) >= std::numeric_limits::max()) ORT_THROW("shape.Size() must >=0"); - void* p_data = allocator->AllocArray(static_cast(shape_size), p_type->Size()); + void* p_data = nullptr; + if(shape_size > 0) + p_data = allocator->AllocArray(static_cast(shape_size), p_type->Size()); Init(p_type, shape, p_data, allocator, offset); }