Browse Source

Fixed a leak in OwnedArray.

tags/2021-05-28
jules 13 years ago
parent
commit
fab78ea09e
2 changed files with 12 additions and 5 deletions
  1. +1
    -0
      modules/juce_core/containers/juce_Array.h
  2. +11
    -5
      modules/juce_core/containers/juce_OwnedArray.h

+ 1
- 0
modules/juce_core/containers/juce_Array.h View File

@@ -142,6 +142,7 @@ public:
#if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
Array& operator= (Array&& other) noexcept
{
const ScopedLockType lock (getLock());
data = static_cast <ArrayAllocationBase<ElementType, TypeOfCriticalSectionToUse>&&> (other.data);
numUsed = other.numUsed;
other.numUsed = 0;


+ 11
- 5
modules/juce_core/containers/juce_OwnedArray.h View File

@@ -70,7 +70,7 @@ public:
*/
~OwnedArray()
{
clear (true);
deleteAllObjects();
}
#if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS
@@ -83,6 +83,9 @@ public:
OwnedArray& operator= (OwnedArray&& other) noexcept
{
const ScopedLockType lock (getLock());
deleteAllObjects();
data = static_cast <ArrayAllocationBase <ObjectClass*, TypeOfCriticalSectionToUse>&&> (other.data);
numUsed = other.numUsed;
other.numUsed = 0;
@@ -97,10 +100,7 @@ public:
const ScopedLockType lock (getLock());
if (deleteObjects)
{
while (numUsed > 0)
delete data.elements [--numUsed];
}
deleteAllObjects();
data.setAllocatedSize (0);
numUsed = 0;
@@ -854,6 +854,12 @@ private:
ArrayAllocationBase <ObjectClass*, TypeOfCriticalSectionToUse> data;
int numUsed;
void deleteAllObjects()
{
while (numUsed > 0)
delete data.elements [--numUsed];
}
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OwnedArray);
};


Loading…
Cancel
Save