Skip to content

Commit

Permalink
Fix ~DeltaTree try to delete uninitialized members (#3903) (#3917)
Browse files Browse the repository at this point in the history
close #3902
  • Loading branch information
ti-chi-bot authored Apr 13, 2022
1 parent 6806724 commit 202a14d
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions dbms/src/Storages/DeltaMerge/DeltaTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ class DTEntryIterator
{
using LeafPtr = DTLeaf<M, F, S> *;

LeafPtr leaf;
LeafPtr leaf = nullptr;
size_t pos;
Int64 delta;

Expand Down Expand Up @@ -553,8 +553,8 @@ class DTEntriesCopy : Allocator

const size_t entry_count;
const Int64 delta;
UInt64 * const sids;
DTMutation * const mutations;
UInt64 * const sids = nullptr;
DTMutation * const mutations = nullptr;

public:
DTEntriesCopy(LeafPtr left_leaf, size_t entry_count_, Int64 delta_)
Expand All @@ -578,8 +578,10 @@ class DTEntriesCopy : Allocator

~DTEntriesCopy()
{
this->free(sids, sizeof(UInt64) * entry_count);
this->free(mutations, sizeof(DTMutation) * entry_count);
if (sids)
this->free(sids, sizeof(UInt64) * entry_count);
if (mutations)
this->free(mutations, sizeof(DTMutation) * entry_count);
}

class Iterator
Expand Down Expand Up @@ -728,18 +730,19 @@ class DeltaTree
static_assert(std::is_standard_layout_v<Intern>);

private:
NodePtr root;
LeafPtr left_leaf, right_leaf;
size_t height = 1;
NodePtr root = nullptr;
LeafPtr left_leaf = nullptr;
LeafPtr right_leaf = nullptr;
size_t height = 1;

size_t num_inserts = 0;
size_t num_deletes = 0;
size_t num_entries = 0;

Allocator * allocator;
size_t bytes = 0;
Allocator * allocator = nullptr;
size_t bytes = 0;

Logger * log;
Logger * log = nullptr;

public:
// For test cases only.
Expand Down Expand Up @@ -889,12 +892,16 @@ class DeltaTree

~DeltaTree()
{
if (isLeaf(root))
freeTree<Leaf>((LeafPtr)root);
else
freeTree<Intern>((InternPtr)root);
if (root)
{
if (isLeaf(root))
freeTree<Leaf>((LeafPtr)root);
else
freeTree<Intern>((InternPtr)root);
}

delete allocator;
if (allocator)
delete allocator;

LOG_TRACE(log, "free");
}
Expand Down Expand Up @@ -1480,4 +1487,4 @@ typename DT_CLASS::InternPtr DT_CLASS::afterNodeUpdated(T * node)
#undef DT_CLASS

} // namespace DM
} // namespace DB
} // namespace DB

0 comments on commit 202a14d

Please sign in to comment.