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

Lukasz Marek lukasz.m.luki2 at gmail.com
Mon Oct 27 23:12:08 CET 2014


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-lavd-alsa-implement-get_device_list-callbacks.patch
Type: text/x-patch
Size: 5137 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20141027/26708871/attachment.bin>


More information about the ffmpeg-devel mailing list