ScopedPointer bug?


#1

There seems to be a bug in ScopedPointer::operator= from an rvalue.

To reproduce the bug one can change the JUCE Demo’s AudioLatencyDemo for example:

  • In AudioLatencyDemo::startTest(), remove the if (latencyTester == nullptr) check. It’s ok to create a new LatencyTester each time it seems.
  • Change the expression new LatencyTester (resultsBox) to ScopedPointer<LatencyTester> (new LatencyTester (resultsBox)).
  • Run the JUCE demo (tested here on OS X 10.11.6 with Xcode 8.0 beta 4, on the current develop branch - commit 70530a9) in debug.
  • In the audio latency demo, run the latency more than once. Every time after the first leaks the previous tester object.
  • Quit the JUCE demo. You should now get an assertion error for leaking LatencyTester objects.

This seems to be the offending line: https://github.com/julianstorer/JUCE/commit/a92c7502b4e0246f8b28f214f8b2b52c73bf67c1#commitcomment-18830823

Cheers, Yair


#2

Ah, good catch, thanks!