From 5b5ab0c1a8fc78746d9fd6334d927139f40c3deb Mon Sep 17 00:00:00 2001 From: Siying Dong Date: Thu, 9 Jan 2014 22:25:03 -0800 Subject: [PATCH] [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 --- db/prefix_test.cc | 5 +++-- util/hash_linklist_rep.cc | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/db/prefix_test.cc b/db/prefix_test.cc index 66cef92cb1..ca00c31b35 100644 --- a/db/prefix_test.cc +++ b/db/prefix_test.cc @@ -108,7 +108,6 @@ class PrefixTest { options.min_write_buffer_number_to_merge = FLAGS_min_write_buffer_number_to_merge; - options.comparator = new TestKeyComparator(); options.memtable_prefix_bloom_bits = FLAGS_memtable_prefix_bloom_bits; options.memtable_prefix_bloom_probes = FLAGS_memtable_prefix_bloom_probes; @@ -142,7 +141,9 @@ class PrefixTest { return false; } - PrefixTest() : option_config_(kBegin) { } + PrefixTest() : option_config_(kBegin) { + options.comparator = new TestKeyComparator(); + } ~PrefixTest() { delete options.comparator; } diff --git a/util/hash_linklist_rep.cc b/util/hash_linklist_rep.cc index e53bffbb6a..214ac2c55d 100644 --- a/util/hash_linklist_rep.cc +++ b/util/hash_linklist_rep.cc @@ -125,7 +125,7 @@ class HashLinkListRep : public MemTableRep { class FullListIterator : public MemTableRep::Iterator { public: explicit FullListIterator(FullList* list) - : iter_(list) {} + : iter_(list), full_list_(list) {} virtual ~FullListIterator() { } @@ -177,6 +177,8 @@ class HashLinkListRep : public MemTableRep { } private: FullList::Iterator iter_; + // To destruct with the iterator. + std::unique_ptr full_list_; std::string tmp_; // For passing to EncodeKey };