Commit eebc7e6c authored by Ryan C. Gordon's avatar Ryan C. Gordon

Fix potential memory leaks if CoreAudio initialization fails.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402203
parent 5927dc70
...@@ -315,6 +315,7 @@ static void ...@@ -315,6 +315,7 @@ static void
COREAUDIO_CloseDevice(_THIS) COREAUDIO_CloseDevice(_THIS)
{ {
if (this->hidden != NULL) { if (this->hidden != NULL) {
if (this->hidden->audioUnitOpened) {
OSStatus result = noErr; OSStatus result = noErr;
AURenderCallbackStruct callback; AURenderCallbackStruct callback;
const AudioUnitElement output_bus = 0; const AudioUnitElement output_bus = 0;
...@@ -331,10 +332,12 @@ COREAUDIO_CloseDevice(_THIS) ...@@ -331,10 +332,12 @@ COREAUDIO_CloseDevice(_THIS)
SDL_memset(&callback, '\0', sizeof (AURenderCallbackStruct)); SDL_memset(&callback, '\0', sizeof (AURenderCallbackStruct));
result = AudioUnitSetProperty(this->hidden->audioUnit, result = AudioUnitSetProperty(this->hidden->audioUnit,
kAudioUnitProperty_SetRenderCallback, kAudioUnitProperty_SetRenderCallback,
scope, bus, &callback, sizeof (callback)); scope, bus, &callback,
sizeof (callback));
CloseComponent(this->hidden->audioUnit); CloseComponent(this->hidden->audioUnit);
this->hidden->audioUnitOpened = 0;
}
SDL_free(this->hidden->buffer); SDL_free(this->hidden->buffer);
SDL_free(this->hidden); SDL_free(this->hidden);
this->hidden = NULL; this->hidden = NULL;
...@@ -435,6 +438,8 @@ prepare_audiounit(_THIS, const char *devname, int iscapture, ...@@ -435,6 +438,8 @@ prepare_audiounit(_THIS, const char *devname, int iscapture,
result = OpenAComponent(comp, &this->hidden->audioUnit); result = OpenAComponent(comp, &this->hidden->audioUnit);
CHECK_RESULT("OpenAComponent"); CHECK_RESULT("OpenAComponent");
this->hidden->audioUnitOpened = 1;
// !!! FIXME: this is wrong? // !!! FIXME: this is wrong?
enableIO = ((iscapture) ? 1 : 0); enableIO = ((iscapture) ? 1 : 0);
result = AudioUnitSetProperty(this->hidden->audioUnit, result = AudioUnitSetProperty(this->hidden->audioUnit,
...@@ -544,6 +549,7 @@ COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) ...@@ -544,6 +549,7 @@ COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
} }
if (!valid_datatype) { /* shouldn't happen, but just in case... */ if (!valid_datatype) { /* shouldn't happen, but just in case... */
COREAUDIO_CloseDevice(this);
SDL_SetError("Unsupported audio format"); SDL_SetError("Unsupported audio format");
return 0; return 0;
} }
...@@ -554,6 +560,7 @@ COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture) ...@@ -554,6 +560,7 @@ COREAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
strdesc.mBytesPerFrame * strdesc.mFramesPerPacket; strdesc.mBytesPerFrame * strdesc.mFramesPerPacket;
if (!prepare_audiounit(this, devname, iscapture, &strdesc)) { if (!prepare_audiounit(this, devname, iscapture, &strdesc)) {
COREAUDIO_CloseDevice(this); \
return 0; /* prepare_audiounit() will call SDL_SetError()... */ return 0; /* prepare_audiounit() will call SDL_SetError()... */
} }
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
struct SDL_PrivateAudioData struct SDL_PrivateAudioData
{ {
AudioUnit audioUnit; AudioUnit audioUnit;
int audioUnitInitialized;
void *buffer; void *buffer;
UInt32 bufferOffset; UInt32 bufferOffset;
UInt32 bufferSize; UInt32 bufferSize;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment