diff --git a/components/common/cpp/include/ftl/cuda_common.hpp b/components/common/cpp/include/ftl/cuda_common.hpp index 58e72ceb35c11c6d79ab17e675ce5bf1573018c7..3f004d0c8ffefaf692b84106dea3810e223d70f3 100644 --- a/components/common/cpp/include/ftl/cuda_common.hpp +++ b/components/common/cpp/include/ftl/cuda_common.hpp @@ -59,10 +59,12 @@ class TextureObject { void download(cv::Mat &, cudaStream_t stream=0) const; __host__ void free() { - if (texobj_ != 0) cudaSafeCall( cudaDestroyTextureObject (texobj_) ); - if (ptr_ && needsfree_) cudaFree(ptr_); - ptr_ = nullptr; - texobj_ = 0; + if (needsfree_) { + if (texobj_ != 0) cudaSafeCall( cudaDestroyTextureObject (texobj_) ); + if (ptr_) cudaFree(ptr_); + ptr_ = nullptr; + texobj_ = 0; + } } private: