[FFmpeg-devel] [PATCH] lavd/alsa: fixes ALSA resource leak on closing the PCM handle

James Almer jamrial at gmail.com
Mon May 8 07:14:46 EEST 2017


On 5/8/2017 1:09 AM, Takayuki 'January June' Suwa wrote:
> By avoiding thread race condition (CAS-ing with null handle)
> 
> ---
>  libavdevice/alsa.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/libavdevice/alsa.c b/libavdevice/alsa.c
> index 1bbff30..81187ab 100644
> --- a/libavdevice/alsa.c
> +++ b/libavdevice/alsa.c
> @@ -30,6 +30,7 @@
>  
>  #include <alsa/asoundlib.h>
>  #include "avdevice.h"
> +#include "libavutil/atomic.h"
>  #include "libavutil/avassert.h"
>  #include "libavutil/channel_layout.h"
>  
> @@ -299,13 +300,14 @@ av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
>  av_cold int ff_alsa_close(AVFormatContext *s1)
>  {
>      AlsaData *s = s1->priv_data;
> +    snd_pcm_t *h = avpriv_atomic_ptr_cas((void* volatile *)&s->h, s->h, 0);

The libavutil/atomics wrappers are going to be removed soon once all
code is finally ported. You should instead use C11 atomics for this.

>  
> -    snd_pcm_nonblock(s->h, 0);
> -    snd_pcm_drain(s->h);
> +    snd_pcm_nonblock(h, 0);
> +    snd_pcm_drain(h);
>      av_freep(&s->reorder_buf);
>      if (CONFIG_ALSA_INDEV)
>          ff_timefilter_destroy(s->timefilter);
> -    snd_pcm_close(s->h);
> +    snd_pcm_close(h);
>      return 0;
>  }
>  
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 



More information about the ffmpeg-devel mailing list