From: Ross Bencina Date: Fri, 2 Sep 2016 13:29:20 +0000 (+1000) Subject: hotplug directsound: factor out freeing of device info array to FreeDeviceInfos.... X-Git-Url: https://andrewgundersen.net/repos?a=commitdiff_plain;h=5c5d4fb711b9c3e98a49aacf502932daefc3ca97;p=portaudio hotplug directsound: factor out freeing of device info array to FreeDeviceInfos. Delete some unused variables. --- diff --git a/src/hostapi/dsound/pa_win_ds.c b/src/hostapi/dsound/pa_win_ds.c index ffd95f9..cb30907 100644 --- a/src/hostapi/dsound/pa_win_ds.c +++ b/src/hostapi/dsound/pa_win_ds.c @@ -1391,6 +1391,20 @@ static PaError IsFormatSupported( struct PaUtilHostApiRepresentation *hostApi, } /***********************************************************************************/ +static void FreeDeviceInfos( PaUtilAllocationGroup *allocations, PaDeviceInfo **deviceInfos ) +{ + if( deviceInfos ) + { + if( deviceInfos[0] ) + { + /* all device info structs are allocated in a block so we can destroy them like this */ + PaUtil_GroupFreeMemory( allocations, deviceInfos[0] ); + } + + PaUtil_GroupFreeMemory( allocations, deviceInfos ); + } +} + static PaError ScanDeviceInfos( struct PaUtilHostApiRepresentation *hostApi, PaHostApiIndex hostApiIndex, void **scanResults, int *newDeviceCount ) { PaWinDsHostApiRepresentation *winDsHostApi = (PaWinDsHostApiRepresentation*)hostApi; @@ -1543,15 +1557,7 @@ error: if( outArgument ) { - if( outArgument->deviceInfos ) - { - if( outArgument->deviceInfos[0] ) - { - PaUtil_GroupFreeMemory( winDsHostApi->allocations, outArgument->deviceInfos[0] ); - } - - PaUtil_GroupFreeMemory( winDsHostApi->allocations, outArgument->deviceInfos ); - } + FreeDeviceInfos( winDsHostApi->allocations, outArgument->deviceInfos ); } return result; } @@ -1559,8 +1565,6 @@ error: static PaError CommitDeviceInfos( struct PaUtilHostApiRepresentation *hostApi, PaHostApiIndex index, void *scanResults, int deviceCount ) { PaWinDsHostApiRepresentation *winDsHostApi = (PaWinDsHostApiRepresentation*)hostApi; - PaError result = paNoError; - int i = 0; hostApi->info.deviceCount = 0; hostApi->info.defaultInputDevice = paNoDevice; @@ -1569,8 +1573,7 @@ static PaError CommitDeviceInfos( struct PaUtilHostApiRepresentation *hostApi, P /* Free any old memory which might be in the device info */ if( hostApi->deviceInfos ) { - PaUtil_GroupFreeMemory( winDsHostApi->allocations, hostApi->deviceInfos[0] ); - PaUtil_GroupFreeMemory( winDsHostApi->allocations, hostApi->deviceInfos ); + FreeDeviceInfos( winDsHostApi->allocations, hostApi->deviceInfos ); hostApi->deviceInfos = NULL; } @@ -1592,7 +1595,7 @@ static PaError CommitDeviceInfos( struct PaUtilHostApiRepresentation *hostApi, P PaUtil_GroupFreeMemory( winDsHostApi->allocations, scanDeviceInfosResults ); } - return result; + return paNoError; } static PaError DisposeDeviceInfos( struct PaUtilHostApiRepresentation *hostApi, void *scanResults, int deviceCount ) @@ -1605,8 +1608,7 @@ static PaError DisposeDeviceInfos( struct PaUtilHostApiRepresentation *hostApi, if( scanDeviceInfosResults->deviceInfos ) { - PaUtil_GroupFreeMemory( winDsHostApi->allocations, scanDeviceInfosResults->deviceInfos[0] ); /* all device info structs are allocated in a block so we can destroy them here */ - PaUtil_GroupFreeMemory( winDsHostApi->allocations, scanDeviceInfosResults->deviceInfos ); + FreeDeviceInfos( winDsHostApi->allocations, hostApi->deviceInfos ); } PaUtil_GroupFreeMemory( winDsHostApi->allocations, scanDeviceInfosResults );