@@ -70,6 +70,9 @@ struct alsa_params_obt {
snd_pcm_uframes_t samples;
};
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(snd_pcm_hw_params_t, snd_pcm_hw_params_free)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(snd_pcm_sw_params_t, snd_pcm_sw_params_free)
+
static void GCC_FMT_ATTR (2, 3) alsa_logerr (int err, const char *fmt, ...)
{
va_list ap;
@@ -410,9 +413,9 @@ static void alsa_dump_info (struct alsa_params_req *req,
static void alsa_set_threshold (snd_pcm_t *handle, snd_pcm_uframes_t threshold)
{
int err;
- snd_pcm_sw_params_t *sw_params;
+ g_autoptr(snd_pcm_sw_params_t) sw_params = NULL;
- snd_pcm_sw_params_alloca (&sw_params);
+ snd_pcm_sw_params_malloc(&sw_params);
err = snd_pcm_sw_params_current (handle, sw_params);
if (err < 0) {
@@ -444,7 +447,7 @@ static int alsa_open(bool in, struct alsa_params_req *req,
AudiodevAlsaOptions *aopts = &dev->u.alsa;
AudiodevAlsaPerDirectionOptions *apdo = in ? aopts->in : aopts->out;
snd_pcm_t *handle;
- snd_pcm_hw_params_t *hw_params;
+ g_autoptr(snd_pcm_hw_params_t) hw_params = NULL;
int err;
unsigned int freq, nchannels;
const char *pcm_name = apdo->has_dev ? apdo->dev : "default";
@@ -455,7 +458,7 @@ static int alsa_open(bool in, struct alsa_params_req *req,
freq = req->freq;
nchannels = req->nchannels;
- snd_pcm_hw_params_alloca (&hw_params);
+ snd_pcm_hw_params_malloc(&hw_params);
err = snd_pcm_open (
&handle,
The ALLOCA(3) man-page mentions its "use is discouraged". Define the cleanup functions for the snd_pcm_[hw/sw]_params_t types, and replace the ALSA alloca() calls by equivalent ALSA malloc(). Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> --- audio/alsaaudio.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)