Imported Debian version 2.5.0~trusty1.1
[deb_ffmpeg.git] / ffmpeg / libavcodec / libvorbisdec.c
index b703b655320661c2610faf76014dd053e4686c59..db005725fc7b7da2d58b4f8c24a5e283261e4ea4 100644 (file)
@@ -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;
+        return AVERROR(EINVAL);
     }
 
+    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 = AVERROR_INVALIDDATA;
+                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 = AVERROR_INVALIDDATA;
+        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 = AVERROR_INVALIDDATA;
+            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;
 }