OSDN Git Service

Avert a rare race condition.
authorjstebbins <jstebbins@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Wed, 9 Dec 2009 19:45:57 +0000 (19:45 +0000)
committerjstebbins <jstebbins@b64f7644-9d1e-0410-96f1-a4d463321fa5>
Wed, 9 Dec 2009 19:45:57 +0000 (19:45 +0000)
A bad source can cause reader to call hb_stream_close before
decavcodecviWork ever starts. This causes hb_ffmpeg_context
to access an invalid pointer.  So move the call to hb_ffmpeg_context
to after we check for a 0 length buffer in decavcodecvoiWork
since reader will have sent this to signal that it has reached
the end of the stream.

This does not eliminate the race condition, but it does make it
much less likely to happen and fixes the specific case where we
found this occuring.

git-svn-id: svn://localhost/HandBrake/trunk@3020 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/decavcodec.c

index f8a0699..19bd56c 100644 (file)
@@ -1044,10 +1044,6 @@ static int decavcodecviWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
                              hb_buffer_t ** buf_out )
 {
     hb_work_private_t *pv = w->private_data;
-    if ( ! pv->context )
-    {
-        init_ffmpeg_context( w );
-    }
     hb_buffer_t *in = *buf_in;
     *buf_in = NULL;
 
@@ -1055,7 +1051,7 @@ static int decavcodecviWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
     if ( in->size == 0 )
     {
         /* flush any frames left in the decoder */
-        while ( decodeFrame( pv, NULL, 0 ) )
+        while ( pv->context && decodeFrame( pv, NULL, 0 ) )
         {
         }
         flushDelayQueue( pv );
@@ -1064,6 +1060,11 @@ static int decavcodecviWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
         return HB_WORK_DONE;
     }
 
+    if ( ! pv->context )
+    {
+        init_ffmpeg_context( w );
+    }
+
     int64_t pts = in->start;
     if( pts >= 0 )
     {