From 9d007e9f099fbaeeb8e9394a61b5f6552c64c5d7 Mon Sep 17 00:00:00 2001 From: David Reid Date: Sun, 16 Oct 2016 07:53:22 +1000 Subject: [PATCH] Use snd_pcm_hw/sw_params_alloca() instead of *malloc() --- mini_al.h | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/mini_al.h b/mini_al.h index 7c2e7365..0f60b7c2 100644 --- a/mini_al.h +++ b/mini_al.h @@ -1791,10 +1791,7 @@ mal_result mal_device_init__alsa(mal_device* pDevice, mal_device_type type, mal_ } snd_pcm_hw_params_t* pHWParams = NULL; - if (snd_pcm_hw_params_malloc(&pHWParams) < 0) { - mal_device_uninit__alsa(pDevice); - return mal_post_error(pDevice, "[ALSA] Failed to allocate snd_pcm_hw_params_t.", MAL_OUT_OF_MEMORY); - } + snd_pcm_hw_params_alloca(&pHWParams); if (snd_pcm_hw_params_any((snd_pcm_t*)pDevice->alsa.pPCM, pHWParams) < 0) { snd_pcm_hw_params_free(pHWParams); @@ -1856,15 +1853,10 @@ mal_result mal_device_init__alsa(mal_device* pDevice, mal_device_type type, mal_ return mal_post_error(pDevice, "[ALSA] Failed to set hardware parameters. snd_pcm_hw_params() failed.", MAL_ALSA_FAILED_TO_SET_SW_PARAMS); } - snd_pcm_hw_params_free(pHWParams); - - + snd_pcm_sw_params_t* pSWParams = NULL; - if (snd_pcm_sw_params_malloc(&pSWParams) < 0) { - mal_device_uninit__alsa(pDevice); - return mal_post_error(pDevice, "[ALSA] Failed to allocate software parameters. snd_pcm_dw_params_malloc() failed.", MAL_OUT_OF_MEMORY); - } + snd_pcm_sw_params_alloca(&pSWParams); if (snd_pcm_sw_params_current((snd_pcm_t*)pDevice->alsa.pPCM, pSWParams) != 0) { snd_pcm_sw_params_free(pSWParams); @@ -1892,8 +1884,6 @@ mal_result mal_device_init__alsa(mal_device* pDevice, mal_device_type type, mal_ return mal_post_error(pDevice, "[ALSA] Failed to set software parameters. snd_pcm_sw_params() failed.", MAL_ALSA_FAILED_TO_SET_SW_PARAMS); } - snd_pcm_sw_params_free(pSWParams); - // If we're _not_ using mmap we need to use an intermediary buffer.