From fab78ea09e31834002fbfffed2d73cb19b6a10a7 Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 23 Jul 2012 09:21:59 +0100 Subject: [PATCH] Fixed a leak in OwnedArray. --- modules/juce_core/containers/juce_Array.h | 1 + modules/juce_core/containers/juce_OwnedArray.h | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/juce_core/containers/juce_Array.h b/modules/juce_core/containers/juce_Array.h index d5d260f67b..a231a77521 100644 --- a/modules/juce_core/containers/juce_Array.h +++ b/modules/juce_core/containers/juce_Array.h @@ -142,6 +142,7 @@ public: #if JUCE_COMPILER_SUPPORTS_MOVE_SEMANTICS Array& operator= (Array&& other) noexcept { + const ScopedLockType lock (getLock()); data = static_cast &&> (other.data); numUsed = other.numUsed; other.numUsed = 0; diff --git a/modules/juce_core/containers/juce_OwnedArray.h b/modules/juce_core/containers/juce_OwnedArray.h index 13ce71759c..adf7fac1ee 100644 --- a/modules/juce_core/containers/juce_OwnedArray.h +++ b/modules/juce_core/containers/juce_OwnedArray.h @@ -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 &&> (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 data; int numUsed; + void deleteAllObjects() + { + while (numUsed > 0) + delete data.elements [--numUsed]; + } + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (OwnedArray); };