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

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…

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

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

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

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

This seems to solve things for getPresets():

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

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

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;

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 (?)

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

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.

Nice!!! :smiley:

We seem to be all good now

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