mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-19 14:17:41 +02:00
Do CFRelease only inside destructors, in AudioUnitEffects.cpp ...
... may fix a memory leak in AudioUnitEffect::SupportsAutomation
This commit is contained in:
parent
eb6ba1ed7a
commit
0bb17c174e
@ -42,6 +42,22 @@
|
||||
|
||||
#include "AudioUnitEffect.h"
|
||||
|
||||
struct CFReleaser
|
||||
{ void operator () (const void *p) const { if (p) CFRelease(p); } };
|
||||
template <typename T>
|
||||
using CFunique_ptr = std::unique_ptr<T, CFReleaser>;
|
||||
|
||||
struct AudioUnitParameterInfoEx : AudioUnitParameterInfo
|
||||
{
|
||||
~AudioUnitParameterInfoEx ()
|
||||
{
|
||||
if ((flags & kAudioUnitParameterFlag_HasCFNameString)
|
||||
&&
|
||||
(flags & kAudioUnitParameterFlag_CFNameRelease))
|
||||
CFRelease( cfNameString );
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Module registration entry point
|
||||
//
|
||||
@ -228,6 +244,8 @@ void AudioUnitEffectsModule::LoadAudioUnitsOfType(OSType inAUType,
|
||||
{
|
||||
CFStringRef cfName;
|
||||
result = AudioComponentCopyName(component, &cfName);
|
||||
CFunique_ptr<const __CFString> uName{ cfName };
|
||||
|
||||
if (result == noErr)
|
||||
{
|
||||
wxString name = wxCFStringRef::AsString(cfName);
|
||||
@ -237,8 +255,6 @@ void AudioUnitEffectsModule::LoadAudioUnitsOfType(OSType inAUType,
|
||||
FromOSType(found.componentType).c_str(),
|
||||
FromOSType(found.componentSubType).c_str(),
|
||||
name.c_str()));
|
||||
|
||||
CFRelease(cfName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -566,27 +582,26 @@ void AudioUnitEffectExportDialog::OnOk(wxCommandEvent & WXUNUSED(evt))
|
||||
&size);
|
||||
|
||||
// And convert it to XML
|
||||
CFDataRef xml = CFPropertyListCreateXMLData(kCFAllocatorDefault,
|
||||
content);
|
||||
CFunique_ptr<const __CFData> xml {
|
||||
CFPropertyListCreateXMLData(kCFAllocatorDefault, content)
|
||||
};
|
||||
if (xml)
|
||||
{
|
||||
// Create the CFURL for the path
|
||||
CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
|
||||
wxCFStringRef(path),
|
||||
kCFURLPOSIXPathStyle,
|
||||
false);
|
||||
CFunique_ptr<const __CFURL> url {
|
||||
CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
|
||||
wxCFStringRef(path),
|
||||
kCFURLPOSIXPathStyle,
|
||||
false)
|
||||
};
|
||||
if (url)
|
||||
{
|
||||
SInt32 error;
|
||||
Boolean res = CFURLWriteDataAndPropertiesToResource(url,
|
||||
xml,
|
||||
Boolean res = CFURLWriteDataAndPropertiesToResource(url.get(),
|
||||
xml.get(),
|
||||
NULL,
|
||||
&error);
|
||||
CFRelease(url);
|
||||
}
|
||||
|
||||
// Get rid of the XML data
|
||||
CFRelease(xml);
|
||||
}
|
||||
|
||||
// And continue to the next selected preset
|
||||
@ -730,10 +745,13 @@ void AudioUnitEffectImportDialog::OnOk(wxCommandEvent & WXUNUSED(evt))
|
||||
mList->GetItemText(sel).c_str());
|
||||
|
||||
// Create the CFURL for the path
|
||||
CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
|
||||
wxCFStringRef(path),
|
||||
kCFURLPOSIXPathStyle,
|
||||
false);
|
||||
CFunique_ptr<const __CFURL> url {
|
||||
CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
|
||||
wxCFStringRef(path),
|
||||
kCFURLPOSIXPathStyle,
|
||||
false)
|
||||
};
|
||||
|
||||
if (!url)
|
||||
{
|
||||
continue;
|
||||
@ -742,24 +760,24 @@ void AudioUnitEffectImportDialog::OnOk(wxCommandEvent & WXUNUSED(evt))
|
||||
CFDataRef xml;
|
||||
SInt32 error;
|
||||
Boolean res = CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,
|
||||
url,
|
||||
url.get(),
|
||||
&xml,
|
||||
NULL,
|
||||
NULL,
|
||||
&error);
|
||||
CFRelease(url);
|
||||
CFunique_ptr<const __CFData> uxml { xml };
|
||||
|
||||
if (!res)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
CFPropertyListRef content;
|
||||
content = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
|
||||
xml,
|
||||
kCFPropertyListImmutable,
|
||||
NULL);
|
||||
CFRelease(xml);
|
||||
CFunique_ptr<char> content {
|
||||
(char*)CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
|
||||
xml,
|
||||
kCFPropertyListImmutable,
|
||||
NULL)
|
||||
};
|
||||
|
||||
if (!content)
|
||||
{
|
||||
@ -772,7 +790,6 @@ void AudioUnitEffectImportDialog::OnOk(wxCommandEvent & WXUNUSED(evt))
|
||||
0,
|
||||
&content,
|
||||
sizeof(content));
|
||||
CFRelease(content);
|
||||
|
||||
mEffect->SaveUserPreset(mEffect->mHost->GetUserPresetsGroup(mList->GetItemText(sel)));
|
||||
}
|
||||
@ -961,7 +978,7 @@ bool AudioUnitEffect::SupportsAutomation()
|
||||
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
AudioUnitParameterInfo info;
|
||||
AudioUnitParameterInfoEx info;
|
||||
dataSize = sizeof(info);
|
||||
result = AudioUnitGetProperty(mUnit,
|
||||
kAudioUnitProperty_ParameterInfo,
|
||||
@ -1501,7 +1518,7 @@ bool AudioUnitEffect::GetAutomationParameters(EffectAutomationParameters & parms
|
||||
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
AudioUnitParameterInfo info;
|
||||
AudioUnitParameterInfoEx info;
|
||||
dataSize = sizeof(info);
|
||||
result = AudioUnitGetProperty(mUnit,
|
||||
kAudioUnitProperty_ParameterInfo,
|
||||
@ -1519,10 +1536,6 @@ bool AudioUnitEffect::GetAutomationParameters(EffectAutomationParameters & parms
|
||||
if (info.flags & kAudioUnitParameterFlag_HasCFNameString)
|
||||
{
|
||||
name = wxCFStringRef::AsString(info.cfNameString);
|
||||
if (info.flags & kAudioUnitParameterFlag_CFNameRelease)
|
||||
{
|
||||
CFRelease(info.cfNameString);
|
||||
}
|
||||
}
|
||||
|
||||
if (name.IsEmpty())
|
||||
@ -1583,7 +1596,7 @@ bool AudioUnitEffect::SetAutomationParameters(EffectAutomationParameters & parms
|
||||
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
AudioUnitParameterInfo info;
|
||||
AudioUnitParameterInfoEx info;
|
||||
dataSize = sizeof(info);
|
||||
result = AudioUnitGetProperty(mUnit,
|
||||
kAudioUnitProperty_ParameterInfo,
|
||||
@ -1601,10 +1614,6 @@ bool AudioUnitEffect::SetAutomationParameters(EffectAutomationParameters & parms
|
||||
if (info.flags & kAudioUnitParameterFlag_HasCFNameString)
|
||||
{
|
||||
name = wxCFStringRef::AsString(info.cfNameString);
|
||||
if (info.flags & kAudioUnitParameterFlag_CFNameRelease)
|
||||
{
|
||||
CFRelease(info.cfNameString);
|
||||
}
|
||||
}
|
||||
|
||||
if (name.IsEmpty())
|
||||
@ -1669,6 +1678,7 @@ bool AudioUnitEffect::LoadFactoryPreset(int id)
|
||||
0,
|
||||
&array,
|
||||
&dataSize);
|
||||
CFunique_ptr < const __CFArray > uarray { array };
|
||||
if (result != noErr)
|
||||
{
|
||||
return false;
|
||||
@ -1697,8 +1707,6 @@ bool AudioUnitEffect::LoadFactoryPreset(int id)
|
||||
AUParameterListenerNotify(NULL, NULL, &aup);
|
||||
}
|
||||
|
||||
CFRelease(array);
|
||||
|
||||
return result == noErr;
|
||||
}
|
||||
|
||||
@ -1721,6 +1729,7 @@ wxArrayString AudioUnitEffect::GetFactoryPresets()
|
||||
0,
|
||||
&array,
|
||||
&dataSize);
|
||||
CFunique_ptr< const __CFArray > uarray { array };
|
||||
if (result == noErr)
|
||||
{
|
||||
for (CFIndex i = 0, cnt = CFArrayGetCount(array); i < cnt; i++)
|
||||
@ -1728,7 +1737,6 @@ wxArrayString AudioUnitEffect::GetFactoryPresets()
|
||||
AUPreset *preset = (AUPreset *) CFArrayGetValueAtIndex(array, i);
|
||||
presets.Add(wxCFStringRef::AsString(preset->presetName));
|
||||
}
|
||||
CFRelease(array);
|
||||
}
|
||||
|
||||
return presets;
|
||||
|
Loading…
x
Reference in New Issue
Block a user