[vlc-devel] commit: Do not realloc a block already given to ffmpeg. (Laurent Aimar )

git version control git at videolan.org
Thu Oct 8 22:04:16 CEST 2009


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Thu Oct  8 21:53:31 2009 +0200| [b89c2b2ac347d4a05846342d5995750cc799e1f2] | committer: Laurent Aimar 

Do not realloc a block already given to ffmpeg.

It avoids a potential segfault after a silent avcodec audio API breakage.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b89c2b2ac347d4a05846342d5995750cc799e1f2
---

 modules/codec/avcodec/audio.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/modules/codec/avcodec/audio.c b/modules/codec/avcodec/audio.c
index 2f353b1..b2cb902 100644
--- a/modules/codec/avcodec/audio.c
+++ b/modules/codec/avcodec/audio.c
@@ -78,6 +78,8 @@ struct decoder_sys_t
     int64_t i_previous_layout;
 };
 
+#define BLOCK_FLAG_PRIVATE_REALLOCATED (1 << BLOCK_FLAG_PRIVATE_SHIFT)
+
 static void SetupOutputFormat( decoder_t *p_dec, bool b_trust );
 
 /*****************************************************************************
@@ -306,11 +308,16 @@ aout_buffer_t * DecodeAudio ( decoder_t *p_dec, block_t **pp_block )
         return NULL;
     }
 
-    *pp_block = p_block = block_Realloc( p_block, 0, p_block->i_buffer + FF_INPUT_BUFFER_PADDING_SIZE );
-    if( !p_block )
-        return NULL;
-    p_block->i_buffer -= FF_INPUT_BUFFER_PADDING_SIZE;
-    memset( &p_block->p_buffer[p_block->i_buffer], 0, FF_INPUT_BUFFER_PADDING_SIZE );
+    if( (p_block->i_flags & BLOCK_FLAG_PRIVATE_REALLOCATED) == 0 )
+    {
+        *pp_block = p_block = block_Realloc( p_block, 0, p_block->i_buffer + FF_INPUT_BUFFER_PADDING_SIZE );
+        if( !p_block )
+            return NULL;
+        p_block->i_buffer -= FF_INPUT_BUFFER_PADDING_SIZE;
+        memset( &p_block->p_buffer[p_block->i_buffer], 0, FF_INPUT_BUFFER_PADDING_SIZE );
+
+        p_block->i_flags |= BLOCK_FLAG_PRIVATE_REALLOCATED;
+    }
 
     do
     {




More information about the vlc-devel mailing list