Skip to content

Commit 5b5ab0c

Browse files
committed
[Performance Branch] Fix memory leak in HashLinkListRep.GetIterator()
Summary: Full list constructed for full iterator can be leaked. This was a bug introduced when I copy the full iterator codes from hash skip list to hash link list. This patch fixes it. Test Plan: Run valgrind test against db_test and make sure the memory leak is fixed Reviewers: kailiu, haobo Reviewed By: kailiu CC: igor, leveldb Differential Revision: https://reviews.facebook.net/D15093
1 parent 237a3da commit 5b5ab0c

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

db/prefix_test.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ class PrefixTest {
108108
options.min_write_buffer_number_to_merge =
109109
FLAGS_min_write_buffer_number_to_merge;
110110

111-
options.comparator = new TestKeyComparator();
112111
options.memtable_prefix_bloom_bits = FLAGS_memtable_prefix_bloom_bits;
113112
options.memtable_prefix_bloom_probes = FLAGS_memtable_prefix_bloom_probes;
114113

@@ -142,7 +141,9 @@ class PrefixTest {
142141
return false;
143142
}
144143

145-
PrefixTest() : option_config_(kBegin) { }
144+
PrefixTest() : option_config_(kBegin) {
145+
options.comparator = new TestKeyComparator();
146+
}
146147
~PrefixTest() {
147148
delete options.comparator;
148149
}

util/hash_linklist_rep.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class HashLinkListRep : public MemTableRep {
125125
class FullListIterator : public MemTableRep::Iterator {
126126
public:
127127
explicit FullListIterator(FullList* list)
128-
: iter_(list) {}
128+
: iter_(list), full_list_(list) {}
129129

130130
virtual ~FullListIterator() {
131131
}
@@ -177,6 +177,8 @@ class HashLinkListRep : public MemTableRep {
177177
}
178178
private:
179179
FullList::Iterator iter_;
180+
// To destruct with the iterator.
181+
std::unique_ptr<FullList> full_list_;
180182
std::string tmp_; // For passing to EncodeKey
181183
};
182184

0 commit comments

Comments
 (0)