[vlc-commits] mux: avi: fix leak on format failure

Francois Cartegnie git at videolan.org
Sun Mar 22 16:28:01 CET 2015


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat Mar 21 18:48:06 2015 +0100| [b955f8603cfe9a533abefa5b0bb5cbfe3c7eb59f] | committer: Francois Cartegnie

mux: avi: fix leak on format failure

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

 modules/mux/avi.c |   27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/modules/mux/avi.c b/modules/mux/avi.c
index 1cdea1d..48d4ca2 100644
--- a/modules/mux/avi.c
+++ b/modules/mux/avi.c
@@ -317,14 +317,15 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
 
             p_stream->p_bih = NULL;
 
-            p_stream->p_wf  = malloc( sizeof( WAVEFORMATEX ) +
-                                      p_input->p_fmt->i_extra );
-            if( !p_stream->p_wf )
+            WAVEFORMATEX *p_wf  = malloc( sizeof( WAVEFORMATEX ) +
+                                  p_input->p_fmt->i_extra );
+            if( !p_wf )
             {
                 free( p_input->p_sys );
+                p_input->p_sys = NULL;
                 return VLC_ENOMEM;
             }
-#define p_wf p_stream->p_wf
+
             p_wf->cbSize = p_input->p_fmt->i_extra;
             if( p_wf->cbSize > 0 )
             {
@@ -390,9 +391,12 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
                                       p_wf->nSamplesPerSec * p_wf->nChannels;
                     break;
                 default:
+                    free( p_wf );
+                    free( p_input->p_sys );
+                    p_input->p_sys = NULL;
                     return VLC_EGENERIC;
             }
-#undef p_wf
+            p_stream->p_wf = p_wf;
             break;
         case VIDEO_ES:
             p_stream->i_cat = VIDEO_ES;
@@ -405,14 +409,15 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
                 p_sys->i_stream_video = p_sys->i_streams;
             }
             p_stream->p_wf  = NULL;
-            p_stream->p_bih = malloc( sizeof( VLC_BITMAPINFOHEADER ) +
-                                      p_input->p_fmt->i_extra );
-            if( !p_stream->p_bih )
+            VLC_BITMAPINFOHEADER *p_bih = malloc( sizeof( VLC_BITMAPINFOHEADER ) +
+                                                 p_input->p_fmt->i_extra );
+            if( !p_bih )
             {
                 free( p_input->p_sys );
+                p_input->p_sys = NULL;
                 return VLC_ENOMEM;
             }
-#define p_bih p_stream->p_bih
+
             p_bih->biSize  = sizeof( VLC_BITMAPINFOHEADER ) +
                              p_input->p_fmt->i_extra;
             if( p_input->p_fmt->i_extra > 0 )
@@ -439,9 +444,11 @@ static int AddStream( sout_mux_t *p_mux, sout_input_t *p_input )
                     p_bih->biCompression = p_input->p_fmt->i_original_fourcc ?: p_input->p_fmt->i_codec;
                     break;
             }
-#undef p_bih
+            p_stream->p_bih = p_bih;
             break;
         default:
+            free( p_input->p_sys );
+            p_input->p_sys = NULL;
             return( VLC_EGENERIC );
     }
     p_stream->i_totalsize = 0;



More information about the vlc-commits mailing list