[FFmpeg-devel] [PATCH] lavd/alsa: implement get_device_list callbacks

Lukasz Marek lukasz.m.luki2 at gmail.com
Sat Nov 1 01:09:21 CET 2014


On 27.10.2014 23:12, Lukasz Marek wrote:
> On 26.10.2014 23:27, Michael Niedermayer wrote:
>>> +/* ported from alsa-utils/aplay.c */
>>> +int ff_alsa_get_device_list(AVDeviceInfoList *device_list,
>>> snd_pcm_stream_t stream_type)
>>> +{
>>> +    int ret = 0;
>>> +    void **hints, **n;
>>> +    char *name = NULL, *descr = NULL, *io = NULL, *tmp;
>>> +    AVDeviceInfo *new_device = NULL;
>>> +    const char *filter = stream_type == SND_PCM_STREAM_PLAYBACK ?
>>> "Output" : "Input";
>>> +
>>> +    if (snd_device_name_hint(-1, "pcm", &hints) < 0)
>>> +        return AVERROR_EXTERNAL;
>>> +    n = hints;
>>> +    while (*n) {
>>> +        tmp = snd_device_name_get_hint(*n, "NAME");
>>> +        name = av_strdup(tmp);
>>> +        if (tmp && !name) {
>>> +            ret = AVERROR(ENOMEM);
>>> +            goto fail;
>>> +        }
>>> +        free(tmp);
>>> +        tmp = snd_device_name_get_hint(*n, "DESC");
>>> +        descr = av_strdup(tmp);
>>> +        if (tmp && !descr) {
>>> +            ret = AVERROR(ENOMEM);
>>> +            goto fail;
>>> +        }
>>> +        free(tmp);
>>> +        tmp = snd_device_name_get_hint(*n, "IOID");
>>> +        io = av_strdup(tmp);
>>> +        if (tmp && !io) {
>>> +            ret = AVERROR(ENOMEM);
>>> +            goto fail;
>>> +        }
>>> +        free(tmp);
>>
>> doesnt mem leak in case of the goto fails ?
>> i dont see where its freed
>
> I intended to free before ifs, but I'm a victim of routine...
> I noticed it can be done more clever anyway, so one more patch attached.

Pushed.


More information about the ffmpeg-devel mailing list