diff mbox

[FFmpeg-devel,3/6] avformat/apngenc: Add deinit function

Message ID 20191023125944.10292-3-andreas.rheinhardt@gmail.com
State Accepted
Commit 26aa04991e02f5fb83ffe177fbd832d7d7deb2fb
Headers show

Commit Message

Andreas Rheinhardt Oct. 23, 2019, 12:59 p.m. UTC
Prevents memleaks when the trailer is never written (e.g. when there was
a write error when writing the header).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/apngenc.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

James Almer Oct. 30, 2019, 6:30 p.m. UTC | #1
On 10/23/2019 9:59 AM, Andreas Rheinhardt wrote:
> Prevents memleaks when the trailer is never written (e.g. when there was
> a write error when writing the header).
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/apngenc.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)

This fixes ticket #8347, so applied. Thanks.
diff mbox

Patch

diff --git a/libavformat/apngenc.c b/libavformat/apngenc.c
index 77c1c916c2..88cd8054d6 100644
--- a/libavformat/apngenc.c
+++ b/libavformat/apngenc.c
@@ -251,7 +251,6 @@  static int apng_write_trailer(AVFormatContext *format_context)
 
     if (apng->prev_packet) {
         ret = flush_packet(format_context, NULL);
-        av_freep(&apng->prev_packet);
         if (ret < 0)
             return ret;
     }
@@ -266,12 +265,18 @@  static int apng_write_trailer(AVFormatContext *format_context)
         apng_write_chunk(io_context, MKBETAG('a', 'c', 'T', 'L'), buf, 8);
     }
 
-    av_freep(&apng->extra_data);
-    apng->extra_data = 0;
-
     return 0;
 }
 
+static void apng_deinit(AVFormatContext *s)
+{
+    APNGMuxContext *apng = s->priv_data;
+
+    av_packet_free(&apng->prev_packet);
+    av_freep(&apng->extra_data);
+    apng->extra_data_size = 0;
+}
+
 #define OFFSET(x) offsetof(APNGMuxContext, x)
 #define ENC AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
@@ -300,6 +305,7 @@  AVOutputFormat ff_apng_muxer = {
     .write_header   = apng_write_header,
     .write_packet   = apng_write_packet,
     .write_trailer  = apng_write_trailer,
+    .deinit         = apng_deinit,
     .priv_class     = &apng_muxer_class,
     .flags          = AVFMT_VARIABLE_FPS,
 };