[FFmpeg-cvslog] avformat/format: Fix registering a format more than once and related races

Michael Niedermayer git at videolan.org
Fri Aug 26 15:41:02 EEST 2016


ffmpeg | branch: release/2.8 | Michael Niedermayer <michael at niedermayer.cc> | Thu Apr  7 17:26:56 2016 +0200| [4a0b0cffc15ae8db0e28a0733bcb065c2c477960] | committer: Michael Niedermayer

avformat/format: Fix registering a format more than once and related races

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
(cherry picked from commit 4cc896ea5f06f8b1ebcde6d876d9c5b59ef9a016)

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4a0b0cffc15ae8db0e28a0733bcb065c2c477960
---

 libavformat/format.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/libavformat/format.c b/libavformat/format.c
index 7df06b7..1fe4b2d 100644
--- a/libavformat/format.c
+++ b/libavformat/format.c
@@ -62,20 +62,24 @@ void av_register_input_format(AVInputFormat *format)
 {
     AVInputFormat **p = last_iformat;
 
-    format->next = NULL;
-    while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
+    // Note, format could be added after the first 2 checks but that implies that *p is no longer NULL
+    while(p != &format->next && !format->next && avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
         p = &(*p)->next;
-    last_iformat = &format->next;
+
+    if (!format->next)
+        last_iformat = &format->next;
 }
 
 void av_register_output_format(AVOutputFormat *format)
 {
     AVOutputFormat **p = last_oformat;
 
-    format->next = NULL;
-    while(*p || avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
+    // Note, format could be added after the first 2 checks but that implies that *p is no longer NULL
+    while(p != &format->next && !format->next && avpriv_atomic_ptr_cas((void * volatile *)p, NULL, format))
         p = &(*p)->next;
-    last_oformat = &format->next;
+
+    if (!format->next)
+        last_oformat = &format->next;
 }
 
 int av_match_ext(const char *filename, const char *extensions)



More information about the ffmpeg-cvslog mailing list