[FFmpeg-cvslog] avformat/webpenc: Fix memleak when trailer is never written

Andreas Rheinhardt git at videolan.org
Sat Apr 3 01:17:58 EEST 2021


ffmpeg | branch: release/4.4 | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Thu Mar 18 23:27:57 2021 +0100| [a57ba45eb4f5a0beefc833012420605ad6c992ee] | committer: Andreas Rheinhardt

avformat/webpenc: Fix memleak when trailer is never written

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 at gmail.com>
(cherry picked from commit 3903c139a9cb13cf66178d7f262b8bcc9fa4be5a)

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=a57ba45eb4f5a0beefc833012420605ad6c992ee
---

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

diff --git a/libavformat/webpenc.c b/libavformat/webpenc.c
index b74c141d2c..99aa23bad4 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)
 #define ENC AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
@@ -214,6 +221,7 @@ AVOutputFormat ff_webp_muxer = {
     .write_header   = webp_write_header,
     .write_packet   = webp_write_packet,
     .write_trailer  = webp_write_trailer,
+    .deinit         = webp_deinit,
     .priv_class     = &webp_muxer_class,
     .flags          = AVFMT_VARIABLE_FPS,
 };



More information about the ffmpeg-cvslog mailing list