]> git.sesse.net Git - vlc/commitdiff
twolame: add error checking
authorTristan Matthews <tmatth@videolan.org>
Sat, 27 Sep 2014 17:47:06 +0000 (13:47 -0400)
committerTristan Matthews <tmatth@videolan.org>
Tue, 30 Sep 2014 01:04:57 +0000 (21:04 -0400)
modules/codec/twolame.c

index 20ef952b1423b5f6e07333df6e00019ada558e14..3257b76e5fde5ddf90e1a2cbda8a7b22144d8053 100644 (file)
@@ -274,6 +274,8 @@ static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
             return NULL;
 
         p_block = block_Alloc( i_used );
+        if( !p_block )
+            return NULL;
         memcpy( p_block->p_buffer, p_sys->p_out_buffer, i_used );
         p_block->i_length = CLOCK_FREQ *
                 (mtime_t)MPEG_FRAME_SIZE / (mtime_t)p_enc->fmt_out.audio.i_rate;
@@ -302,8 +304,21 @@ static block_t *Encode( encoder_t *p_enc, block_t *p_aout_buf )
         i_used = twolame_encode_buffer_interleaved( p_sys->p_twolame,
                                p_sys->p_buffer, MPEG_FRAME_SIZE,
                                p_sys->p_out_buffer, MAX_CODED_FRAME_SIZE );
+        /* On error, buffer samples and return what was already encoded */
+        if( i_used < 0 )
+        {
+            msg_Err( p_enc, "encoder error: %d", i_used );
+            break;
+        }
+
         p_sys->i_nb_samples = 0;
         p_block = block_Alloc( i_used );
+        if( !p_block )
+        {
+            if( p_chain )
+                block_Release( p_chain );
+            return NULL;
+        }
         memcpy( p_block->p_buffer, p_sys->p_out_buffer, i_used );
         p_block->i_length = CLOCK_FREQ *
                 (mtime_t)MPEG_FRAME_SIZE / (mtime_t)p_enc->fmt_out.audio.i_rate;