]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
alsa: Avoid alloca().
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 2 Jan 2015 20:10:56 +0000 (20:10 +0000)
committerAndre Noll <maan@tuebingen.mpg.de>
Sat, 4 Apr 2015 17:51:23 +0000 (17:51 +0000)
It is not in POSIX.1-2001, and its use is discouraged. Fortunately,
the alsa library provides also variants which call ordinary malloc(),
so use these instead.

alsa_mix.c
alsa_write.c

index 5a46963e56722c2abc3a162401179c58122497db..cad58af0a9481bd8cb7985cf87b431685f537c01 100644 (file)
@@ -100,11 +100,13 @@ static bool channel_has_playback(snd_mixer_selem_channel_id_t chn,
 
 static char *alsa_mix_get_channels(struct mixer_handle *handle)
 {
 
 static char *alsa_mix_get_channels(struct mixer_handle *handle)
 {
+       int ret;
        char *list = NULL;
        snd_mixer_selem_id_t *sid;
        snd_mixer_elem_t *elem;
 
        char *list = NULL;
        snd_mixer_selem_id_t *sid;
        snd_mixer_elem_t *elem;
 
-       snd_mixer_selem_id_alloca(&sid);
+       ret = snd_mixer_selem_id_malloc(&sid);
+       assert(ret >= 0);
        elem = snd_mixer_first_elem(handle->mixer);
        for (; elem; elem = snd_mixer_elem_next(elem)) {
                char *tmp = list;
        elem = snd_mixer_first_elem(handle->mixer);
        for (; elem; elem = snd_mixer_elem_next(elem)) {
                char *tmp = list;
@@ -122,6 +124,7 @@ static char *alsa_mix_get_channels(struct mixer_handle *handle)
                        name);
                free(tmp);
        }
                        name);
                free(tmp);
        }
+       snd_mixer_selem_id_free(sid);
        return list;
 }
 
        return list;
 }
 
@@ -133,7 +136,8 @@ static int alsa_mix_set_channel(struct mixer_handle *h,
 
        if (!mixer_channel)
                mixer_channel = "Master";
 
        if (!mixer_channel)
                mixer_channel = "Master";
-       snd_mixer_selem_id_alloca(&sid);
+       ret = snd_mixer_selem_id_malloc(&sid);
+       assert(ret >= 0);
        snd_mixer_selem_id_set_index(sid, selem_id);
        snd_mixer_selem_id_set_name(sid, mixer_channel);
        h->elem = snd_mixer_find_selem(h->mixer, sid);
        snd_mixer_selem_id_set_index(sid, selem_id);
        snd_mixer_selem_id_set_name(sid, mixer_channel);
        h->elem = snd_mixer_find_selem(h->mixer, sid);
@@ -141,21 +145,27 @@ static int alsa_mix_set_channel(struct mixer_handle *h,
                PARA_NOTICE_LOG("unable to find simple control '%s',%i\n",
                        snd_mixer_selem_id_get_name(sid),
                        snd_mixer_selem_id_get_index(sid));
                PARA_NOTICE_LOG("unable to find simple control '%s',%i\n",
                        snd_mixer_selem_id_get_name(sid),
                        snd_mixer_selem_id_get_index(sid));
-               return -E_BAD_CHANNEL;
+               ret = -E_BAD_CHANNEL;
+               goto out;
        }
        ret = snd_mixer_selem_get_playback_volume_range(h->elem,
                &h->pmin, &h->pmax);
        if (ret < 0) {
                PARA_NOTICE_LOG("unable to get %s range (%s): %s\n",
                        mixer_channel, h->card, snd_strerror(ret));
        }
        ret = snd_mixer_selem_get_playback_volume_range(h->elem,
                &h->pmin, &h->pmax);
        if (ret < 0) {
                PARA_NOTICE_LOG("unable to get %s range (%s): %s\n",
                        mixer_channel, h->card, snd_strerror(ret));
-               return -E_ALSA_MIX_RANGE;
+               ret = -E_ALSA_MIX_RANGE;
+               goto out;
        }
        if (h->pmin >= h->pmax) {
                PARA_NOTICE_LOG("alsa reported %s range %ld-%ld (%s)\n",
                        mixer_channel, h->pmin, h->pmax, h->card);
        }
        if (h->pmin >= h->pmax) {
                PARA_NOTICE_LOG("alsa reported %s range %ld-%ld (%s)\n",
                        mixer_channel, h->pmin, h->pmax, h->card);
-               return -E_ALSA_MIX_RANGE;
+               ret = -E_ALSA_MIX_RANGE;
+               goto out;
        }
        }
-       return 1;
+       ret = 1;
+out:
+       snd_mixer_selem_id_free(sid);
+       return ret;
 }
 
 static int alsa_mix_get(struct mixer_handle *h)
 }
 
 static int alsa_mix_get(struct mixer_handle *h)
index b0b21f2be4a6ac64c2d940f499b59757273db743..63a7055be35fab00847379be8ce3785a48312818 100644 (file)
@@ -74,8 +74,8 @@ static snd_pcm_format_t get_alsa_pcm_format(enum sample_format sf)
 static int alsa_init(struct private_alsa_write_data *pad,
                struct alsa_write_args_info *conf)
 {
 static int alsa_init(struct private_alsa_write_data *pad,
                struct alsa_write_args_info *conf)
 {
-       snd_pcm_hw_params_t *hwparams;
-       snd_pcm_sw_params_t *swparams;
+       snd_pcm_hw_params_t *hwparams = NULL;
+       snd_pcm_sw_params_t *swparams = NULL;
        snd_pcm_uframes_t start_threshold, stop_threshold;
        snd_pcm_uframes_t buffer_size, period_size;
        snd_output_t *output_log;
        snd_pcm_uframes_t start_threshold, stop_threshold;
        snd_pcm_uframes_t buffer_size, period_size;
        snd_output_t *output_log;
@@ -89,7 +89,8 @@ static int alsa_init(struct private_alsa_write_data *pad,
                SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
        if (ret < 0)
                goto fail;
                SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
        if (ret < 0)
                goto fail;
-       snd_pcm_hw_params_alloca(&hwparams);
+       ret = snd_pcm_hw_params_malloc(&hwparams);
+       assert(ret >= 0);
        msg = "Broken alsa configuration";
        ret = snd_pcm_hw_params_any(pad->handle, hwparams);
        if (ret < 0)
        msg = "Broken alsa configuration";
        ret = snd_pcm_hw_params_any(pad->handle, hwparams);
        if (ret < 0)
@@ -140,7 +141,8 @@ static int alsa_init(struct private_alsa_write_data *pad,
                goto fail;
 
        /* software parameter setup */
                goto fail;
 
        /* software parameter setup */
-       snd_pcm_sw_params_alloca(&swparams);
+       ret = snd_pcm_sw_params_malloc(&swparams);
+       assert(ret >= 0);
        snd_pcm_sw_params_current(pad->handle, swparams);
        snd_pcm_sw_params_set_avail_min(pad->handle, swparams, period_size);
        if (buffer_size < 1)
        snd_pcm_sw_params_current(pad->handle, swparams);
        snd_pcm_sw_params_set_avail_min(pad->handle, swparams, period_size);
        if (buffer_size < 1)
@@ -190,13 +192,18 @@ static int alsa_init(struct private_alsa_write_data *pad,
                }
                snd_output_close(output_log);
        }
                }
                snd_output_close(output_log);
        }
-       return 1;
+       ret = 1;
+       goto out;
 fail:
        if (ret < 0)
                PARA_ERROR_LOG("%s: %s\n", msg, snd_strerror(-ret));
        else
                PARA_ERROR_LOG("%s\n", msg);
 fail:
        if (ret < 0)
                PARA_ERROR_LOG("%s: %s\n", msg, snd_strerror(-ret));
        else
                PARA_ERROR_LOG("%s\n", msg);
-       return -E_ALSA;
+       ret = -E_ALSA;
+out:
+       snd_pcm_hw_params_free(hwparams);
+       snd_pcm_sw_params_free(swparams);
+       return ret;
 }
 
 static void alsa_write_pre_select(struct sched *s, void *context)
 }
 
 static void alsa_write_pre_select(struct sched *s, void *context)