diff mbox

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

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

Commit Message

Andreas Rheinhardt Oct. 23, 2019, 12:59 p.m. UTC
Prevents memleaks in situations where the trailer isn't written, e.g.
because of errors during writing the header.

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

Comments

Michael Niedermayer Oct. 24, 2019, 5:50 p.m. UTC | #1
On Wed, Oct 23, 2019 at 02:59:44PM +0200, Andreas Rheinhardt wrote:
> Prevents memleaks in situations where the trailer isn't written, e.g.
> because of errors during writing the header.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/icoenc.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavformat/icoenc.c b/libavformat/icoenc.c
index e641f7bdc7..975c3466bf 100644
--- a/libavformat/icoenc.c
+++ b/libavformat/icoenc.c
@@ -183,11 +183,16 @@  static int ico_write_trailer(AVFormatContext *s)
         avio_wl32(pb, ico->images[i].offset);
     }
 
-    av_freep(&ico->images);
-
     return 0;
 }
 
+static void ico_deinit(AVFormatContext *s)
+{
+    IcoMuxContext *ico = s->priv_data;
+
+    av_freep(&ico->images);
+}
+
 AVOutputFormat ff_ico_muxer = {
     .name           = "ico",
     .long_name      = NULL_IF_CONFIG_SMALL("Microsoft Windows ICO"),
@@ -199,5 +204,6 @@  AVOutputFormat ff_ico_muxer = {
     .write_header   = ico_write_header,
     .write_packet   = ico_write_packet,
     .write_trailer  = ico_write_trailer,
+    .deinit         = ico_deinit,
     .flags          = AVFMT_NOTIMESTAMPS,
 };