diff mbox series

[FFmpeg-devel,17/18] avformat/webpenc: Fix memleak when trailer is never written

Message ID 20210319055904.2264501-17-andreas.rheinhardt@gmail.com
State Accepted
Commit 3903c139a9cb13cf66178d7f262b8bcc9fa4be5a
Headers show
Series [FFmpeg-devel,01/18] libavformat/utils: Fix indentation | expand


Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt March 19, 2021, 5:59 a.m. UTC
When the trailer is never written (or when a stream switches from
non-animation mode to animation mode mid-stream), a cached packet
(if existing) would leak. Fix this by adding a deinit function.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
AVFormatInternal.parse_pkt is completely unused for muxers, so it can be
reused in this muxer and this deinit function removed again. See
https://github.com/mkver/FFmpeg/commits/packet_reuse for more.

 libavformat/webpenc.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series


diff --git a/libavformat/webpenc.c b/libavformat/webpenc.c
index d5edf89289..ed8325c02d 100644
--- a/libavformat/webpenc.c
+++ b/libavformat/webpenc.c
@@ -191,6 +191,13 @@  static int webp_write_trailer(AVFormatContext *s)
     return 0;
+static void webp_deinit(AVFormatContext *s)
+    WebpContext *w = s->priv_data;
+    av_packet_unref(&w->last_pkt);
 #define OFFSET(x) offsetof(WebpContext, x)
 static const AVOption options[] = {
@@ -214,6 +221,7 @@  AVOutputFormat ff_webp_muxer = {
     .init           = webp_init,
     .write_packet   = webp_write_packet,
     .write_trailer  = webp_write_trailer,
+    .deinit         = webp_deinit,
     .priv_class     = &webp_muxer_class,
     .flags          = AVFMT_VARIABLE_FPS,