From 06a8de0b8b8f94160edba0c47a62cd9d10c0799c Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Sat, 6 Oct 2018 18:14:54 +0200 Subject: [PATCH] genericvector: Rewrite code to satisfy static code analyzer Warning from LGTM: Resource data_ is acquired by class GenericVector but not released in the destructor. LGTM complains about data_ not being deleted in the destructor. The destructor calls the clear() method, but the delete there was conditional which confuses the static code analyzer. Signed-off-by: Stefan Weil --- src/ccutil/genericvector.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/ccutil/genericvector.h b/src/ccutil/genericvector.h index 661f1e11ff..e6878dd1cc 100644 --- a/src/ccutil/genericvector.h +++ b/src/ccutil/genericvector.h @@ -866,15 +866,14 @@ void GenericVector::set_compare_callback( // Clear the array, calling the callback function if any. template void GenericVector::clear() { - if (size_reserved_ > 0) { - if (clear_cb_ != nullptr) - for (int i = 0; i < size_used_; ++i) - clear_cb_->Run(data_[i]); - delete[] data_; - data_ = nullptr; - size_used_ = 0; - size_reserved_ = 0; + if (size_reserved_ > 0 && clear_cb_ != nullptr) { + for (int i = 0; i < size_used_; ++i) + clear_cb_->Run(data_[i]); } + delete[] data_; + data_ = nullptr; + size_used_ = 0; + size_reserved_ = 0; delete clear_cb_; clear_cb_ = nullptr; delete compare_cb_;