From bc6240e989490ba5650834861a2a7efe4cf06ee2 Mon Sep 17 00:00:00 2001 From: Nikolay Chirkov Date: Mon, 14 Nov 2022 02:29:30 -0800 Subject: [PATCH] Zero-initialize id etc. members in Tensor PiperOrigin-RevId: 488308585 --- mediapipe/framework/formats/tensor.cc | 4 ++++ mediapipe/framework/formats/tensor.h | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/mediapipe/framework/formats/tensor.cc b/mediapipe/framework/formats/tensor.cc index ef0cddea4..c31eba350 100644 --- a/mediapipe/framework/formats/tensor.cc +++ b/mediapipe/framework/formats/tensor.cc @@ -387,7 +387,9 @@ void Tensor::Move(Tensor* src) { src->cpu_buffer_ = nullptr; #if MEDIAPIPE_METAL_ENABLED device_ = src->device_; + src->device_ = nil; command_buffer_ = src->command_buffer_; + src->command_buffer_ = nil; metal_buffer_ = src->metal_buffer_; src->metal_buffer_ = nil; #endif // MEDIAPIPE_METAL_ENABLED @@ -431,6 +433,8 @@ void Tensor::Invalidate() { DeallocateVirtualMemory(cpu_buffer_, AlignToPageSize(bytes())); } metal_buffer_ = nil; + command_buffer_ = nil; + device_ = nil; cpu_buffer_ = nullptr; #if MEDIAPIPE_OPENGL_ES_VERSION >= MEDIAPIPE_OPENGL_ES_30 // Don't need to wait for the resource to be deleted bacause if will be diff --git a/mediapipe/framework/formats/tensor.h b/mediapipe/framework/formats/tensor.h index ff9da3ec6..ecd63c8c6 100644 --- a/mediapipe/framework/formats/tensor.h +++ b/mediapipe/framework/formats/tensor.h @@ -384,9 +384,9 @@ class Tensor { mutable void* cpu_buffer_ = nullptr; void AllocateCpuBuffer() const; #if MEDIAPIPE_METAL_ENABLED - mutable id command_buffer_; - mutable id device_; - mutable id metal_buffer_; + mutable id command_buffer_ = nil; + mutable id device_ = nil; + mutable id metal_buffer_ = nil; void AllocateMtlBuffer(id device) const; #endif // MEDIAPIPE_METAL_ENABLED