From 91d13a5866bd8040eec5e9f9086a50f66f57d5d1 Mon Sep 17 00:00:00 2001 From: rossb Date: Sun, 24 Jan 2010 09:34:48 +0000 Subject: [PATCH] clean up resources better if DirectSound OpenStream fails --- src/hostapi/dsound/pa_win_ds.c | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/hostapi/dsound/pa_win_ds.c b/src/hostapi/dsound/pa_win_ds.c index 322a614..b20cbdf 100644 --- a/src/hostapi/dsound/pa_win_ds.c +++ b/src/hostapi/dsound/pa_win_ds.c @@ -1585,6 +1585,8 @@ static PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi, PaError result = paNoError; PaWinDsHostApiRepresentation *winDsHostApi = (PaWinDsHostApiRepresentation*)hostApi; PaWinDsStream *stream = 0; + int bufferProcessorIsInitialized = 0; + int streamRepresentationIsInitialized = 0; PaWinDsDeviceInfo *inputWinDsDeviceInfo, *outputWinDsDeviceInfo; PaDeviceInfo *inputDeviceInfo, *outputDeviceInfo; int inputChannelCount, outputChannelCount; @@ -1721,6 +1723,8 @@ static PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi, &winDsHostApi->blockingStreamInterface, streamCallback, userData ); } + streamRepresentationIsInitialized = 1; + PaUtil_InitializeCpuLoadMeasurer( &stream->cpuLoadMeasurer, sampleRate ); @@ -1763,6 +1767,7 @@ static PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi, if( result != paNoError ) goto error; + bufferProcessorIsInitialized = 1; stream->streamRepresentation.streamInfo.inputLatency = PaUtil_GetBufferProcessorInputLatency(&stream->bufferProcessor); /* FIXME: not initialised anywhere else */ @@ -1930,6 +1935,38 @@ error: if( stream->processingCompleted != NULL ) CloseHandle( stream->processingCompleted ); + if( stream->pDirectSoundOutputBuffer ) + { + IDirectSoundBuffer_Stop( stream->pDirectSoundOutputBuffer ); + IDirectSoundBuffer_Release( stream->pDirectSoundOutputBuffer ); + stream->pDirectSoundOutputBuffer = NULL; + } + + if( stream->pDirectSoundInputBuffer ) + { + IDirectSoundCaptureBuffer_Stop( stream->pDirectSoundInputBuffer ); + IDirectSoundCaptureBuffer_Release( stream->pDirectSoundInputBuffer ); + stream->pDirectSoundInputBuffer = NULL; + } + + if( stream->pDirectSoundCapture ) + { + IDirectSoundCapture_Release( stream->pDirectSoundCapture ); + stream->pDirectSoundCapture = NULL; + } + + if( stream->pDirectSound ) + { + IDirectSound_Release( stream->pDirectSound ); + stream->pDirectSound = NULL; + } + + if( bufferProcessorIsInitialized ) + PaUtil_TerminateBufferProcessor( &stream->bufferProcessor ); + + if( streamRepresentationIsInitialized ) + PaUtil_TerminateStreamRepresentation( &stream->streamRepresentation ); + PaUtil_FreeMemory( stream ); } -- 2.43.0