Fix memory leak

Summary: There is a memory leak because TransformRepFactory does not delete its SliceTransform pointer. This patch adds a delete to the destructor.

Test Plan:
make check
make valgrind_check

Reviewers: dhruba, emayanke, haobo

Reviewed By: dhruba

CC: leveldb

Differential Revision: https://reviews.facebook.net/D12513
This commit is contained in:
Jim Paton 2013-08-23 15:39:49 -07:00
parent 4504c99030
commit 5c3b254ef2
2 changed files with 9 additions and 3 deletions

View File

@ -180,7 +180,8 @@ public:
// over the entire collection is rare.
//
// Parameters:
// transform: The SliceTransform to bucket user keys on.
// transform: The SliceTransform to bucket user keys on. TransformRepFactory
// assumes it does not own the pointer.
// bucket_count: Passed to the constructor of the underlying
// std::unordered_map of each TransformRep. On initialization, the
// underlying array will be at least bucket_count size.
@ -206,9 +207,13 @@ public:
//
// Parameters: See TransformRepFactory.
class UnsortedRepFactory : public TransformRepFactory {
const SliceTransform* transform_;
public:
explicit UnsortedRepFactory(size_t bucket_count = 0, size_t num_locks = 1000)
: TransformRepFactory(NewNoopTransform(), bucket_count, num_locks) { }
: TransformRepFactory(transform_ = NewNoopTransform(),
bucket_count,
num_locks) { }
virtual ~UnsortedRepFactory() { delete transform_; }
};
// PrefixHashReps bin user keys based on a fixed-size prefix. This optimizes for

View File

@ -149,7 +149,8 @@ class PrefixHashRep : public TransformRep {
public:
PrefixHashRep(const KeyComparator& compare, Arena* arena,
const SliceTransform* transform, size_t bucket_size,
size_t num_locks) : TransformRep(compare, arena, transform,
size_t num_locks)
: TransformRep(compare, arena, transform,
bucket_size, num_locks) { }
virtual std::shared_ptr<MemTableRep::Iterator> GetPrefixIterator(