Fix memory leaks in Map and Set

This commit is contained in:
Daniel Chappuis 2018-04-04 07:31:49 +02:00
parent 1aebf7703a
commit 0307a1d9be
2 changed files with 32 additions and 26 deletions
src/containers

View File

@ -380,7 +380,9 @@ class Map {
/// Copy constructor
Map(const Map<K, V>& map)
:mNbUsedEntries(map.mNbUsedEntries), mNbFreeEntries(map.mNbFreeEntries), mCapacity(map.mCapacity),
mAllocator(map.mAllocator), mFreeIndex(map.mFreeIndex) {
mBuckets(nullptr), mEntries(nullptr), mAllocator(map.mAllocator), mFreeIndex(map.mFreeIndex) {
if (mCapacity > 0) {
// Allocate memory for the buckets
mBuckets = static_cast<int*>(mAllocator.allocate(mCapacity * sizeof(int)));
@ -402,6 +404,7 @@ class Map {
}
}
}
}
/// Destructor
~Map() {

View File

@ -379,7 +379,9 @@ class Set {
/// Copy constructor
Set(const Set<V>& set)
:mNbUsedEntries(set.mNbUsedEntries), mNbFreeEntries(set.mNbFreeEntries), mCapacity(set.mCapacity),
mAllocator(set.mAllocator), mFreeIndex(set.mFreeIndex) {
mBuckets(nullptr), mEntries(nullptr), mAllocator(set.mAllocator), mFreeIndex(set.mFreeIndex) {
if (mCapacity > 0) {
// Allocate memory for the buckets
mBuckets = static_cast<int*>(mAllocator.allocate(mCapacity * sizeof(int)));
@ -401,6 +403,7 @@ class Set {
}
}
}
}
/// Destructor
~Set() {