added some security code, release CF string to avoid memory leaking

This commit is contained in:
Volker Fischer 2015-11-20 18:23:42 +00:00
parent 62af55929f
commit cdeb89e514

View file

@ -51,7 +51,7 @@ CSound::CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* ar
// Get available input/output devices -------------------------------------- // Get available input/output devices --------------------------------------
UInt32 iPropertySize; UInt32 iPropertySize = 0;
AudioObjectPropertyAddress stPropertyAddress; AudioObjectPropertyAddress stPropertyAddress;
stPropertyAddress.mScope = kAudioObjectPropertyScopeGlobal; stPropertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
@ -204,7 +204,7 @@ void CSound::GetAudioDeviceInfos ( const AudioDeviceID DeviceID,
bIsOutput = ( iPropertySize > 0 ); // check if any output streams are available bIsOutput = ( iPropertySize > 0 ); // check if any output streams are available
// get property name // get property name
CFStringRef sPropertyStringValue; CFStringRef sPropertyStringValue = NULL;
stPropertyAddress.mSelector = kAudioObjectPropertyName; stPropertyAddress.mSelector = kAudioObjectPropertyName;
stPropertyAddress.mScope = kAudioObjectPropertyScopeGlobal; stPropertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
@ -252,8 +252,9 @@ QString CSound::LoadAndInitializeDriver ( int iDriverIdx )
QString CSound::CheckDeviceCapabilities ( const int iDriverIdx ) QString CSound::CheckDeviceCapabilities ( const int iDriverIdx )
{ {
UInt32 iPropertySize; UInt32 iPropertySize;
Float64 inputSampleRate;
AudioStreamBasicDescription CurDevStreamFormat; AudioStreamBasicDescription CurDevStreamFormat;
Float64 inputSampleRate = 0;
Float64 outputSampleRate = 0;
const Float64 fSystemSampleRate = static_cast<Float64> ( SYSTEM_SAMPLE_RATE_HZ ); const Float64 fSystemSampleRate = static_cast<Float64> ( SYSTEM_SAMPLE_RATE_HZ );
AudioObjectPropertyAddress stPropertyAddress; AudioObjectPropertyAddress stPropertyAddress;
@ -290,7 +291,6 @@ QString CSound::CheckDeviceCapabilities ( const int iDriverIdx )
// check output device sample rate // check output device sample rate
iPropertySize = sizeof ( Float64 ); iPropertySize = sizeof ( Float64 );
Float64 outputSampleRate;
AudioObjectGetPropertyData ( audioOutputDevice[iDriverIdx], AudioObjectGetPropertyData ( audioOutputDevice[iDriverIdx],
&stPropertyAddress, &stPropertyAddress,
@ -423,7 +423,7 @@ QString CSound::CheckDeviceCapabilities ( const int iDriverIdx )
// get the channel names of the input device // get the channel names of the input device
for ( int iCurInCH = 0; iCurInCH < iNumInChan; iCurInCH++ ) for ( int iCurInCH = 0; iCurInCH < iNumInChan; iCurInCH++ )
{ {
CFStringRef sPropertyStringValue; CFStringRef sPropertyStringValue = NULL;
stPropertyAddress.mSelector = kAudioObjectPropertyElementName; stPropertyAddress.mSelector = kAudioObjectPropertyElementName;
stPropertyAddress.mElement = iCurInCH + 1; stPropertyAddress.mElement = iCurInCH + 1;
@ -457,7 +457,7 @@ QString CSound::CheckDeviceCapabilities ( const int iDriverIdx )
// get the channel names of the output device // get the channel names of the output device
for ( int iCurOutCH = 0; iCurOutCH < iNumOutChan; iCurOutCH++ ) for ( int iCurOutCH = 0; iCurOutCH < iNumOutChan; iCurOutCH++ )
{ {
CFStringRef sPropertyStringValue; CFStringRef sPropertyStringValue = NULL;
stPropertyAddress.mSelector = kAudioObjectPropertyElementName; stPropertyAddress.mSelector = kAudioObjectPropertyElementName;
stPropertyAddress.mElement = iCurOutCH + 1; stPropertyAddress.mElement = iCurOutCH + 1;
@ -656,6 +656,7 @@ UInt32 CSound::SetBufferSize ( AudioDeviceID& audioDeviceID,
// first set the value // first set the value
UInt32 iSizeBufValue = sizeof ( UInt32 ); UInt32 iSizeBufValue = sizeof ( UInt32 );
AudioObjectSetPropertyData ( audioDeviceID, AudioObjectSetPropertyData ( audioDeviceID,
&stPropertyAddress, &stPropertyAddress,
0, 0,
@ -664,7 +665,8 @@ UInt32 CSound::SetBufferSize ( AudioDeviceID& audioDeviceID,
&iPrefBufferSize ); &iPrefBufferSize );
// read back which value is actually used // read back which value is actually used
UInt32 iActualMonoBufferSize; UInt32 iActualMonoBufferSize = 0;
AudioObjectGetPropertyData ( audioDeviceID, AudioObjectGetPropertyData ( audioDeviceID,
&stPropertyAddress, &stPropertyAddress,
0, 0,
@ -774,8 +776,12 @@ OSStatus CSound::callbackIO ( AudioDeviceID inDevice,
return kAudioHardwareNoError; return kAudioHardwareNoError;
} }
bool CSound::ConvertCFStringToQString ( const CFStringRef stringRef, QString& sOut ) bool CSound::ConvertCFStringToQString ( const CFStringRef stringRef,
QString& sOut )
{ {
// check if the string reference is a valid pointer
if ( stringRef != NULL )
{
// first check if the string is not empty // first check if the string is not empty
if ( CFStringGetLength ( stringRef ) > 0 ) if ( CFStringGetLength ( stringRef ) > 0 )
{ {
@ -795,5 +801,9 @@ bool CSound::ConvertCFStringToQString ( const CFStringRef stringRef, QString& sO
} }
} }
// release the string reference because it is not needed anymore
CFRelease ( stringRef );
}
return false; // not OK return false; // not OK
} }