added some security code, release CF string to avoid memory leaking
This commit is contained in:
parent
62af55929f
commit
cdeb89e514
1 changed files with 31 additions and 21 deletions
|
@ -51,7 +51,7 @@ CSound::CSound ( void (*fpNewProcessCallback) ( CVector<short>& psData, void* ar
|
|||
|
||||
|
||||
// Get available input/output devices --------------------------------------
|
||||
UInt32 iPropertySize;
|
||||
UInt32 iPropertySize = 0;
|
||||
AudioObjectPropertyAddress stPropertyAddress;
|
||||
|
||||
stPropertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
|
||||
|
@ -204,7 +204,7 @@ void CSound::GetAudioDeviceInfos ( const AudioDeviceID DeviceID,
|
|||
bIsOutput = ( iPropertySize > 0 ); // check if any output streams are available
|
||||
|
||||
// get property name
|
||||
CFStringRef sPropertyStringValue;
|
||||
CFStringRef sPropertyStringValue = NULL;
|
||||
|
||||
stPropertyAddress.mSelector = kAudioObjectPropertyName;
|
||||
stPropertyAddress.mScope = kAudioObjectPropertyScopeGlobal;
|
||||
|
@ -252,8 +252,9 @@ QString CSound::LoadAndInitializeDriver ( int iDriverIdx )
|
|||
QString CSound::CheckDeviceCapabilities ( const int iDriverIdx )
|
||||
{
|
||||
UInt32 iPropertySize;
|
||||
Float64 inputSampleRate;
|
||||
AudioStreamBasicDescription CurDevStreamFormat;
|
||||
Float64 inputSampleRate = 0;
|
||||
Float64 outputSampleRate = 0;
|
||||
const Float64 fSystemSampleRate = static_cast<Float64> ( SYSTEM_SAMPLE_RATE_HZ );
|
||||
AudioObjectPropertyAddress stPropertyAddress;
|
||||
|
||||
|
@ -290,7 +291,6 @@ QString CSound::CheckDeviceCapabilities ( const int iDriverIdx )
|
|||
|
||||
// check output device sample rate
|
||||
iPropertySize = sizeof ( Float64 );
|
||||
Float64 outputSampleRate;
|
||||
|
||||
AudioObjectGetPropertyData ( audioOutputDevice[iDriverIdx],
|
||||
&stPropertyAddress,
|
||||
|
@ -423,7 +423,7 @@ QString CSound::CheckDeviceCapabilities ( const int iDriverIdx )
|
|||
// get the channel names of the input device
|
||||
for ( int iCurInCH = 0; iCurInCH < iNumInChan; iCurInCH++ )
|
||||
{
|
||||
CFStringRef sPropertyStringValue;
|
||||
CFStringRef sPropertyStringValue = NULL;
|
||||
|
||||
stPropertyAddress.mSelector = kAudioObjectPropertyElementName;
|
||||
stPropertyAddress.mElement = iCurInCH + 1;
|
||||
|
@ -457,7 +457,7 @@ QString CSound::CheckDeviceCapabilities ( const int iDriverIdx )
|
|||
// get the channel names of the output device
|
||||
for ( int iCurOutCH = 0; iCurOutCH < iNumOutChan; iCurOutCH++ )
|
||||
{
|
||||
CFStringRef sPropertyStringValue;
|
||||
CFStringRef sPropertyStringValue = NULL;
|
||||
|
||||
stPropertyAddress.mSelector = kAudioObjectPropertyElementName;
|
||||
stPropertyAddress.mElement = iCurOutCH + 1;
|
||||
|
@ -656,6 +656,7 @@ UInt32 CSound::SetBufferSize ( AudioDeviceID& audioDeviceID,
|
|||
|
||||
// first set the value
|
||||
UInt32 iSizeBufValue = sizeof ( UInt32 );
|
||||
|
||||
AudioObjectSetPropertyData ( audioDeviceID,
|
||||
&stPropertyAddress,
|
||||
0,
|
||||
|
@ -664,7 +665,8 @@ UInt32 CSound::SetBufferSize ( AudioDeviceID& audioDeviceID,
|
|||
&iPrefBufferSize );
|
||||
|
||||
// read back which value is actually used
|
||||
UInt32 iActualMonoBufferSize;
|
||||
UInt32 iActualMonoBufferSize = 0;
|
||||
|
||||
AudioObjectGetPropertyData ( audioDeviceID,
|
||||
&stPropertyAddress,
|
||||
0,
|
||||
|
@ -774,8 +776,12 @@ OSStatus CSound::callbackIO ( AudioDeviceID inDevice,
|
|||
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
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue