[vlc-devel] [PATCH] decoder_helpers: fix clean order

Thomas Guillem thomas at gllm.fr
Tue Feb 19 13:24:17 CET 2019


The module need to be unloaded before the dec struct is cleaned.

This fixes an undefined behavior with threaded decoders like avcodec when they
called decoder_UpdateVideoFormat()/dec_NewPicture() from an other thread just
before they were unloaded.
---
 src/input/decoder_helpers.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/input/decoder_helpers.c b/src/input/decoder_helpers.c
index 3cc02de8d6..b0a7c1890a 100644
--- a/src/input/decoder_helpers.c
+++ b/src/input/decoder_helpers.c
@@ -48,6 +48,12 @@ void decoder_Init( decoder_t *p_dec, const es_format_t *restrict p_fmt )
 
 void decoder_Clean( decoder_t *p_dec )
 {
+    if ( p_dec->p_module != NULL )
+    {
+        module_unneed(p_dec, p_dec->p_module);
+        p_dec->p_module = NULL;
+    }
+
     es_format_Clean( &p_dec->fmt_in );
     es_format_Clean( &p_dec->fmt_out );
 
@@ -56,11 +62,6 @@ void decoder_Clean( decoder_t *p_dec )
         vlc_meta_Delete(p_dec->p_description);
         p_dec->p_description = NULL;
     }
-    if ( p_dec->p_module != NULL )
-    {
-        module_unneed(p_dec, p_dec->p_module);
-        p_dec->p_module = NULL;
-    }
 }
 
 void decoder_Destroy( decoder_t *p_dec )
-- 
2.20.1



More information about the vlc-devel mailing list