Skip to content

Commit

Permalink
genericvector: Rewrite code to satisfy static code analyzer
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
stweil committed Oct 6, 2018
1 parent 9efedc1 commit 06a8de0
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/ccutil/genericvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -866,15 +866,14 @@ void GenericVector<T>::set_compare_callback(
// Clear the array, calling the callback function if any.
template <typename T>
void GenericVector<T>::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_;
Expand Down

0 comments on commit 06a8de0

Please sign in to comment.