]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/ivfenc.c
avformat/avidec: Fix memleak when allocating DVDemuxContext fails
[ffmpeg] / libavformat / ivfenc.c
index adf72117e93436763cfe4b4ddbf7c8c0595b078a..45e5b238dcbb896d28093e9a2e3c20953a5f8d27 100644 (file)
@@ -53,7 +53,7 @@ static int ivf_write_header(AVFormatContext *s)
     avio_wl16(pb, par->height);
     avio_wl32(pb, s->streams[0]->time_base.den);
     avio_wl32(pb, s->streams[0]->time_base.num);
-    avio_wl64(pb, 0xFFFFFFFFFFFFFFFFULL);
+    avio_wl64(pb, 0xFFFFFFFFFFFFFFFFULL); // length is overwritten at the end of muxing
 
     return 0;
 }
@@ -80,10 +80,12 @@ static int ivf_write_trailer(AVFormatContext *s)
     IVFEncContext *ctx = s->priv_data;
 
     if ((pb->seekable & AVIO_SEEKABLE_NORMAL) && ctx->frame_cnt > 1) {
-        size_t end = avio_tell(pb);
+        int64_t end = avio_tell(pb);
 
         avio_seek(pb, 24, SEEK_SET);
-        avio_wl64(pb, ctx->frame_cnt * ctx->sum_delta_pts / (ctx->frame_cnt - 1));
+        // overwrite the "length" field (duration)
+        avio_wl32(pb, ctx->frame_cnt * ctx->sum_delta_pts / (ctx->frame_cnt - 1));
+        avio_wl32(pb, 0); // zero out unused bytes
         avio_seek(pb, end, SEEK_SET);
     }