Fix memory leaks in Map and Set
This commit is contained in:
parent
1aebf7703a
commit
0307a1d9be
|
@ -380,7 +380,9 @@ class Map {
|
||||||
/// Copy constructor
|
/// Copy constructor
|
||||||
Map(const Map<K, V>& map)
|
Map(const Map<K, V>& map)
|
||||||
:mNbUsedEntries(map.mNbUsedEntries), mNbFreeEntries(map.mNbFreeEntries), mCapacity(map.mCapacity),
|
: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
|
// Allocate memory for the buckets
|
||||||
mBuckets = static_cast<int*>(mAllocator.allocate(mCapacity * sizeof(int)));
|
mBuckets = static_cast<int*>(mAllocator.allocate(mCapacity * sizeof(int)));
|
||||||
|
@ -402,6 +404,7 @@ class Map {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~Map() {
|
~Map() {
|
||||||
|
|
|
@ -379,7 +379,9 @@ class Set {
|
||||||
/// Copy constructor
|
/// Copy constructor
|
||||||
Set(const Set<V>& set)
|
Set(const Set<V>& set)
|
||||||
:mNbUsedEntries(set.mNbUsedEntries), mNbFreeEntries(set.mNbFreeEntries), mCapacity(set.mCapacity),
|
: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
|
// Allocate memory for the buckets
|
||||||
mBuckets = static_cast<int*>(mAllocator.allocate(mCapacity * sizeof(int)));
|
mBuckets = static_cast<int*>(mAllocator.allocate(mCapacity * sizeof(int)));
|
||||||
|
@ -401,6 +403,7 @@ class Set {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Destructor
|
/// Destructor
|
||||||
~Set() {
|
~Set() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user