flacdec: don't create an attached picture stream until we have all information.
authorAnton Khirnov <anton@khirnov.net>
Fri, 6 Jul 2012 20:21:09 +0000 (22:21 +0200)
committerAnton Khirnov <anton@khirnov.net>
Sat, 7 Jul 2012 18:33:44 +0000 (20:33 +0200)
This way we don't end with an invalid stream if parsing the picture
fails.

libavformat/flacdec.c

index f481c10..0be60a4 100644 (file)
@@ -38,10 +38,6 @@ static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
     int type, width, height;
     int len, ret = 0;
 
-    st = avformat_new_stream(s, NULL);
-    if (!st)
-        return AVERROR(ENOMEM);
-
     pb = avio_alloc_context(buf, buf_size, 0, NULL, NULL, NULL, NULL);
     if (!pb)
         return AVERROR(ENOMEM);
@@ -114,6 +110,12 @@ static int parse_picture(AVFormatContext *s, uint8_t *buf, int buf_size)
         goto fail;
     }
 
+    st = avformat_new_stream(s, NULL);
+    if (!st) {
+        ret = AVERROR(ENOMEM);
+        goto fail;
+    }
+
     av_init_packet(&st->attached_pic);
     st->attached_pic.data         = data;
     st->attached_pic.size         = len;