Skip to content

Commit 06a8de0

Browse files
committed
genericvector: Rewrite code to satisfy static code analyzer
Warning from LGTM: Resource data_ is acquired by class GenericVector<FontSpacingInfo *> 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 <sw@weilnetz.de>
1 parent 9efedc1 commit 06a8de0

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/ccutil/genericvector.h

+7-8
Original file line numberDiff line numberDiff line change
@@ -866,15 +866,14 @@ void GenericVector<T>::set_compare_callback(
866866
// Clear the array, calling the callback function if any.
867867
template <typename T>
868868
void GenericVector<T>::clear() {
869-
if (size_reserved_ > 0) {
870-
if (clear_cb_ != nullptr)
871-
for (int i = 0; i < size_used_; ++i)
872-
clear_cb_->Run(data_[i]);
873-
delete[] data_;
874-
data_ = nullptr;
875-
size_used_ = 0;
876-
size_reserved_ = 0;
869+
if (size_reserved_ > 0 && clear_cb_ != nullptr) {
870+
for (int i = 0; i < size_used_; ++i)
871+
clear_cb_->Run(data_[i]);
877872
}
873+
delete[] data_;
874+
data_ = nullptr;
875+
size_used_ = 0;
876+
size_reserved_ = 0;
878877
delete clear_cb_;
879878
clear_cb_ = nullptr;
880879
delete compare_cb_;

0 commit comments

Comments
 (0)