[FFmpeg-devel] [PATCH] lavd/alsa: fixes ALSA resource leak on closing the PCM handle
Takayuki 'January June' Suwa
jjsuwa.sys3175 at gmail.com
Mon May 8 07:09:54 EEST 2017
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);
- 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;
}
More information about the ffmpeg-devel
mailing list