Bug in juce::var getBinaryData()

Hi Jules,

I have a ValueTree with a binary in it, if I use it as:

MemoryBlock* pBlock = myvar.getBinaryData();

it works but leaves a leaked MemoryBlock object on shutdown. So I thought, ScopedPointer to the rescue :)

ScopedPointer<MemoryBlock> pBlock(myvar.getBinaryData());

but that crashes when ScopedPointer exists scope, of course.


Have a careful read of the comment for that method - the pointer it returns isn't a new object, it's just a pointer to the MemoryBlock that the var owns. (Unfortunately I couldn't make it return a MemoryBlock& because it may return nullptr, and it can't return a const MemoryBlock* because you may want to change the data)

If it's leaking, then either you're leaking the var that contains it, or something more subtle is going wrong inside the var class, but I haven't seen any problems like that myself.

Thanks, indeed, my variant holder went out of scope AFTER the leak checking code kicks in. Inheriting DeletedAtShutdown took care of that nicely.