[vlc-devel] [PATCH 2/3] decoder: fix out_pool race condtion

Thomas Guillem thomas at gllm.fr
Fri Nov 27 16:21:43 CET 2020


The ModuleThread is creating it, so it doesn't need a lock for reading,
but it does need a lock for writing it. Indeed, other threads (the
DecoderThread and the input one) are already reading this variable with
the lock held.
---
 src/input/decoder.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index 19b774c49c1..8d67f7ea637 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -449,16 +449,21 @@ static int ModuleThread_UpdateVideoFormat( decoder_t *p_dec, vlc_video_context *
             dpb_size = 2;
             break;
         }
-
-        p_owner->out_pool = picture_pool_NewFromFormat( &p_dec->fmt_out.video,
+        picture_pool_t *pool = picture_pool_NewFromFormat( &p_dec->fmt_out.video,
                             dpb_size + p_dec->i_extra_picture_buffers + 1 );
-        if (p_owner->out_pool == NULL)
+
+        if( pool == NULL)
         {
             msg_Err(p_dec, "Failed to create a pool of %d %4.4s pictures",
                            dpb_size + p_dec->i_extra_picture_buffers + 1,
                            (char*)&p_dec->fmt_out.video.i_chroma);
             return -1;
         }
+
+        vlc_mutex_lock( &p_owner->lock );
+        p_owner->out_pool = pool;
+        vlc_mutex_unlock( &p_owner->lock );
+
     }
 
     vout_configuration_t cfg = {
@@ -544,13 +549,12 @@ static int CreateVoutIfNeeded(vlc_input_decoder_t *p_owner)
 
     DecoderUpdateFormatLocked( p_owner );
     p_owner->fmt.video.i_chroma = p_dec->fmt_out.i_codec;
+    picture_pool_t *pool = p_owner->out_pool;
+    p_owner->out_pool = NULL;
     vlc_mutex_unlock( &p_owner->lock );
 
-     if ( p_owner->out_pool != NULL )
-     {
-         picture_pool_Release( p_owner->out_pool );
-         p_owner->out_pool = NULL;
-     }
+     if ( pool != NULL )
+         picture_pool_Release( pool );
 
     if( p_vout == NULL )
     {
-- 
2.28.0



More information about the vlc-devel mailing list