avformat/rmdec: move packet allocation down
authorMichael Niedermayer <michaelni@gmx.at>
Mon, 23 Dec 2013 17:09:58 +0000 (18:09 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Thu, 26 Dec 2013 03:16:10 +0000 (04:16 +0100)
Fixes memleak
Fixes: msan_uninit-mem_7fc5d73327d4_6192_kuerti.ra
Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavformat/rmdec.c

index 97be4b1cd9374efab53a89ab18005c2ee04cafac..8feef54f60d26261c500df9c9dd05f1145739636 100644 (file)
@@ -255,16 +255,6 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb,
         default:
             av_strlcpy(st->codec->codec_name, buf, sizeof(st->codec->codec_name));
         }
-        if (ast->deint_id == DEINT_ID_INT4 ||
-            ast->deint_id == DEINT_ID_GENR ||
-            ast->deint_id == DEINT_ID_SIPR) {
-            if (st->codec->block_align <= 0 ||
-                ast->audio_framesize * sub_packet_h > (unsigned)INT_MAX ||
-                ast->audio_framesize * sub_packet_h < st->codec->block_align)
-                return AVERROR_INVALIDDATA;
-            if (av_new_packet(&ast->pkt, ast->audio_framesize * sub_packet_h) < 0)
-                return AVERROR(ENOMEM);
-        }
         switch (ast->deint_id) {
         case DEINT_ID_INT4:
             if (ast->coded_framesize > ast->audio_framesize ||
@@ -290,6 +280,16 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb,
             av_log(s, AV_LOG_ERROR, "Unknown interleaver %X\n", ast->deint_id);
             return AVERROR_INVALIDDATA;
         }
+        if (ast->deint_id == DEINT_ID_INT4 ||
+            ast->deint_id == DEINT_ID_GENR ||
+            ast->deint_id == DEINT_ID_SIPR) {
+            if (st->codec->block_align <= 0 ||
+                ast->audio_framesize * sub_packet_h > (unsigned)INT_MAX ||
+                ast->audio_framesize * sub_packet_h < st->codec->block_align)
+                return AVERROR_INVALIDDATA;
+            if (av_new_packet(&ast->pkt, ast->audio_framesize * sub_packet_h) < 0)
+                return AVERROR(ENOMEM);
+        }
 
         if (read_all) {
             avio_r8(pb);