diff options
author | Michael Niedermayer <michael@niedermayer.cc> | 2016-04-07 17:26:56 +0200 |
---|---|---|
committer | Michael Niedermayer <michael@niedermayer.cc> | 2017-08-23 13:15:16 +0200 |
commit | a36a7d3b4387aacffbb14a43f5166d39c5f48ad0 (patch) | |
tree | a91be9b05f0091a7950023eb4c8fc0b412f1b52a | |
parent | a21a9f9d0bed21d3c812a98e08c22537920583bc (diff) | |
download | ffmpeg-a36a7d3b4387aacffbb14a43f5166d39c5f48ad0.tar.gz |
avformat/format: Fix registering a format more than once and related races
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 4cc896ea5f06f8b1ebcde6d876d9c5b59ef9a016)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
-rw-r--r-- | libavformat/format.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/libavformat/format.c b/libavformat/format.c index 1026c8f7a7..b53d367d98 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) |