提交 3a4c197d 编写于 作者: 李寅

Fix buffer ownership bug

上级 35bf09d6
...@@ -72,7 +72,10 @@ class Tensor { ...@@ -72,7 +72,10 @@ class Tensor {
name_(""){}; name_(""){};
Tensor(BufferBase *buffer, DataType dtype) Tensor(BufferBase *buffer, DataType dtype)
: dtype_(dtype), buffer_(buffer), is_buffer_owner_(false), name_("") {} : dtype_(dtype),
buffer_(buffer),
is_buffer_owner_(false),
name_("") {}
Tensor(const BufferSlice &buffer_slice, DataType dtype) Tensor(const BufferSlice &buffer_slice, DataType dtype)
: dtype_(dtype), : dtype_(dtype),
...@@ -166,8 +169,8 @@ class Tensor { ...@@ -166,8 +169,8 @@ class Tensor {
MACE_CHECK(!has_opencl_image(), "Cannot resize image, use ResizeImage."); MACE_CHECK(!has_opencl_image(), "Cannot resize image, use ResizeImage.");
buffer_->Resize(raw_size()); buffer_->Resize(raw_size());
} else { } else {
MACE_CHECK(is_buffer_owner_);
buffer_ = new Buffer(allocator_, raw_size()); buffer_ = new Buffer(allocator_, raw_size());
is_buffer_owner_ = true;
} }
} }
...@@ -176,8 +179,8 @@ class Tensor { ...@@ -176,8 +179,8 @@ class Tensor {
shape_ = shape; shape_ = shape;
image_shape_ = image_shape; image_shape_ = image_shape;
if (buffer_ == nullptr) { if (buffer_ == nullptr) {
MACE_CHECK(is_buffer_owner_);
buffer_ = new Image(image_shape, dtype_); buffer_ = new Image(image_shape, dtype_);
is_buffer_owner_ = true;
} else { } else {
MACE_CHECK(has_opencl_image(), "Cannot ResizeImage buffer, use Resize."); MACE_CHECK(has_opencl_image(), "Cannot ResizeImage buffer, use Resize.");
Image *image = dynamic_cast<Image *>(buffer_); Image *image = dynamic_cast<Image *>(buffer_);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册