[vlc-commits] avcodec/encoder: fix alloc/free of context

Rémi Denis-Courmont git at videolan.org
Sat Sep 13 11:48:52 CEST 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Sep 13 12:43:52 2014 +0300| [15c1b323859cc05de566828ea1e508dcb9dee134] | committer: Rémi Denis-Courmont

avcodec/encoder: fix alloc/free of context

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

 modules/codec/avcodec/encoder.c |    9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index 3704e0f..f2002c0 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -352,6 +352,11 @@ int OpenEncoder( vlc_object_t *p_this )
     p_sys->i_buffer_out = 0;
 
     p_context = avcodec_alloc_context3(p_codec);
+    if( unlikely(p_context == NULL) )
+    {
+        free( p_sys );
+        return VLC_ENOMEM;
+    }
     p_sys->p_context = p_context;
     p_sys->p_context->codec_id = p_sys->p_codec->id;
     p_context->thread_type = 0;
@@ -457,6 +462,7 @@ int OpenEncoder( vlc_object_t *p_this )
         {
             msg_Warn( p_enc, "invalid size %ix%i", p_enc->fmt_in.video.i_visible_width,
                       p_enc->fmt_in.video.i_visible_height );
+            avcodec_free_context( &p_context );
             free( p_sys );
             return VLC_EGENERIC;
         }
@@ -1005,6 +1011,7 @@ error:
     free( p_enc->fmt_out.p_extra );
     av_free( p_sys->p_buffer );
     av_free( p_sys->p_interleave_buf );
+    avcodec_free_context( &p_context );
     free( p_sys );
     return VLC_ENOMEM;
 }
@@ -1404,7 +1411,7 @@ void CloseEncoder( vlc_object_t *p_this )
     vlc_avcodec_lock();
     avcodec_close( p_sys->p_context );
     vlc_avcodec_unlock();
-    av_free( p_sys->p_context );
+    avcodec_free_context( &p_sys->p_context );
 
 
     av_free( p_sys->p_interleave_buf );



More information about the vlc-commits mailing list