]> git.sesse.net Git - vlc/commitdiff
mux: avi: fix leak on format failure
authorFrancois Cartegnie <fcvlcdev@free.fr>
Sat, 21 Mar 2015 17:48:06 +0000 (18:48 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Sun, 22 Mar 2015 15:27:50 +0000 (16:27 +0100)
modules/mux/avi.c

index 1cdea1dd2b761365e6b741eae9694d9ef237e249..48d4ca24d1e9fd0a11a705dc828cd55039b1f814 100644 (file)
@@ -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;