String::toCFString() leaks with JuceAU::getParameterInfo()?


#1

Hey everyone,

I have been noticing that juce::String::toCFString() leaks when called from JuceAU::getParameterInfo() and JuceAU::getPresets(). Has anyone else had similar issues? I am using the latest tip of JUCE, Xcode 3.2, the 10.6 SDK and I am using Apple Instruments and AU Lab for debugging…


#2

Thanks I hadn’t noticed that… I guess this would fix it?

CFStringRef cfName (name.toCFString()); AUBase::FillInParameterName (outParameterInfo, cfName, false); CFRelease (cfName);


#3

That seems to do the trick for getParameterInfo()! :slight_smile:

However there is still one more CFString related leak, located inside of JuceAU::GetPresets()


#4

This seems to solve things for getPresets():

presets[i].presetName = juceFilter->getProgramName(i).isEmpty() 
	? CFSTR("Untitled") : juceFilter->getProgramName(i).toCFString();

#5

Ok, I’ve checked something in now if you want to try it.


#6

I was able to compile your code… However, it still continued to leak and the plugin crashed when the editor was closed. I was able to kind of minimize the issue with the following code. Unfortunately, it still seems to leak when you close and reopen the editor (although less often).

    ComponentResult GetPresets (CFArrayRef* outData) const
    {
        if (outData != nullptr)
        {
            const int numPrograms = juceFilter->getNumPrograms();
            CFMutableArrayRef pArray = CFArrayCreateMutable (0, 
					 numPrograms, 0);
            presetsArray.ensureSize (sizeof (AUPreset) * numPrograms, true);
            AUPreset* const presets = (AUPreset*) presetsArray.getData();
			
            for (int i = 0; i < numPrograms; ++i)
            {
				const String name = juceFilter->getProgramName(i);
				CFStringRef nameRef = (name.isEmpty()
								  ? CFSTR("Untitled") : name.toCFString());
				presets[i].presetNumber = i;
				presets[i].presetName = nameRef;
                CFArrayAppendValue (pArray, presets + i);
            }

            *outData = (CFArrayRef) pArray;
        }

        return noErr;
    }

#7

Ok, but this snippet doesn’t seem to be based on what I checked-in… I changed the MemoryBlock to a HeapBlock, but this code is using a MemoryBlock again (?)


#8

Sorry, I forgot to mention that. I was using the MemoryBlock defined previously.


#9

Avoiding allocating empty strings will obviously make it leak less if some of the strings are empty, but it’s not a fix for the underlying problem!

I’ve checked-in another attempt if you want to have a look.


#10

Nice!!! :smiley:

We seem to be all good now


#11

Sorry to dig this up! We’re seeing a similar looking juce::String::toCFString() leak in JuceAU::addParameters().