[FFmpeg-devel] [PATCH 1/2] lavc/libvorbisdec: fix mem leak in case of init failure

Lukasz Marek lukasz.m.luki2 at gmail.com
Sat Nov 22 22:46:40 CET 2014


Signed-off-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>
---
 libavcodec/libvorbisdec.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/libavcodec/libvorbisdec.c b/libavcodec/libvorbisdec.c
index b703b65..f2c5046 100644
--- a/libavcodec/libvorbisdec.c
+++ b/libavcodec/libvorbisdec.c
@@ -35,17 +35,17 @@ typedef struct OggVorbisDecContext {
 static int oggvorbis_decode_init(AVCodecContext *avccontext) {
     OggVorbisDecContext *context = avccontext->priv_data ;
     uint8_t *p= avccontext->extradata;
-    int i, hsizes[3];
+    int i, hsizes[3], ret;
     unsigned char *headers[3], *extradata = avccontext->extradata;
 
-    vorbis_info_init(&context->vi) ;
-    vorbis_comment_init(&context->vc) ;
-
     if(! avccontext->extradata_size || ! p) {
         av_log(avccontext, AV_LOG_ERROR, "vorbis extradata absent\n");
         return -1;
     }
 
+    vorbis_info_init(&context->vi) ;
+    vorbis_comment_init(&context->vc) ;
+
     if(p[0] == 0 && p[1] == 30) {
         for(i = 0; i < 3; i++){
             hsizes[i] = bytestream_get_be16((const uint8_t **)&p);
@@ -65,7 +65,8 @@ static int oggvorbis_decode_init(AVCodecContext *avccontext) {
             if(offset >= avccontext->extradata_size - 1) {
                 av_log(avccontext, AV_LOG_ERROR,
                        "vorbis header sizes damaged\n");
-                return -1;
+                ret = -1;
+                goto error;
             }
             hsizes[i] += *p;
             offset++;
@@ -83,7 +84,8 @@ static int oggvorbis_decode_init(AVCodecContext *avccontext) {
     } else {
         av_log(avccontext, AV_LOG_ERROR,
                "vorbis initial header len is wrong: %d\n", *p);
-        return -1;
+        ret = -1;
+        goto error;
     }
 
     for(i=0; i<3; i++){
@@ -92,7 +94,8 @@ static int oggvorbis_decode_init(AVCodecContext *avccontext) {
         context->op.packet = headers[i];
         if(vorbis_synthesis_headerin(&context->vi, &context->vc, &context->op)<0){
             av_log(avccontext, AV_LOG_ERROR, "%d. vorbis header damaged\n", i+1);
-            return -1;
+            ret = -1;
+            goto error;
         }
     }
 
@@ -105,6 +108,11 @@ static int oggvorbis_decode_init(AVCodecContext *avccontext) {
     vorbis_block_init(&context->vd, &context->vb);
 
     return 0 ;
+
+  error:
+    vorbis_info_clear(&context->vi);
+    vorbis_comment_clear(&context->vc) ;
+    return ret;
 }
 
 
-- 
1.9.1



More information about the ffmpeg-devel mailing list