1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Fixed a leak in JUCE's std::function compatibility implementation

This commit is contained in:
Tom Poole 2018-08-21 00:17:07 +01:00
parent 0e1722e387
commit f818377914
2 changed files with 26 additions and 7 deletions

View file

@ -62,7 +62,7 @@ namespace FunctionTestsHelpers
struct FunctionObject
{
FunctionObject() {}
FunctionObject() = default;
FunctionObject (const FunctionObject& other)
{
@ -72,6 +72,26 @@ namespace FunctionTestsHelpers
int operator()(int i) const { return bigData->sum() + i; }
std::unique_ptr<BigData> bigData { new BigData() };
JUCE_LEAK_DETECTOR (FunctionObject)
};
struct BigFunctionObject
{
BigFunctionObject() = default;
BigFunctionObject (const BigFunctionObject& other)
{
bigData.reset (new BigData (*other.bigData));
}
int operator()(int i) const { return bigData->sum() + i; }
std::unique_ptr<BigData> bigData { new BigData() };
int stackUsage[32];
JUCE_LEAK_DETECTOR (BigFunctionObject)
};
}
@ -95,13 +115,16 @@ public:
std::function<double(double, double)> f2 (FunctionTestsHelpers::multiply);
expectEquals (6.0, f2 (2.0, 3.0));
}
{
beginTest ("Function objects");
std::function<int(int)> f1 = FunctionTestsHelpers::FunctionObject();
expectEquals (f1 (5), FunctionTestsHelpers::BigData::bigDataSum + 5);
std::function<int(int)> f2 { FunctionTestsHelpers::BigFunctionObject() };
expectEquals (f2 (5), FunctionTestsHelpers::BigData::bigDataSum + 5);
}
{

View file

@ -192,11 +192,7 @@ namespace std
{
if (functorHolderHelper != nullptr)
{
if (functorHolderHelper->getSize() > functorHolderStackSize)
delete[] reinterpret_cast<char*> (functorHolderHelper);
else
functorHolderHelper->~FunctorHolderBase<Result, Arguments...>();
functorHolderHelper->~FunctorHolderBase<Result, Arguments...>();
functorHolderHelper = nullptr;
}
}