diff mbox series

[FFmpeg-devel,1/3] avformat/swfdec: Fix memleaks on error

Message ID 20200920115341.1812809-1-andreas.rheinhardt@gmail.com
State Accepted
Commit 28dc0c20cc51346ba7891a324b35e0ef6295c9dd
Headers show
Series [FFmpeg-devel,1/3] avformat/swfdec: Fix memleaks on error | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 20, 2020, 11:53 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/swfdec.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Andreas Rheinhardt Sept. 23, 2020, 12:09 p.m. UTC | #1
Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/swfdec.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c
> index e427998744..7a74fa3ac7 100644
> --- a/libavformat/swfdec.c
> +++ b/libavformat/swfdec.c
> @@ -146,13 +146,18 @@ static int swf_read_header(AVFormatContext *s)
>          swf->zbuf_out = av_malloc(ZBUF_SIZE);
>          swf->zpb = avio_alloc_context(swf->zbuf_out, ZBUF_SIZE, 0, s,
>                                        zlib_refill, NULL, NULL);
> -        if (!swf->zbuf_in || !swf->zbuf_out || !swf->zpb)
> +        if (!swf->zbuf_in || !swf->zbuf_out || !swf->zpb) {
> +            av_freep(&swf->zbuf_in);
> +            av_freep(&swf->zbuf_out);
> +            avio_context_free(&swf->zpb);
>              return AVERROR(ENOMEM);
> +        }
>          swf->zpb->seekable = 0;
>          if (inflateInit(&swf->zstream) != Z_OK) {
>              av_log(s, AV_LOG_ERROR, "Unable to init zlib context\n");
>              av_freep(&swf->zbuf_in);
>              av_freep(&swf->zbuf_out);
> +            avio_context_free(&swf->zpb);
>              return AVERROR(EINVAL);
>          }
>          pb = swf->zpb;
> 
Will apply.

- Andreas
diff mbox series

Patch

diff --git a/libavformat/swfdec.c b/libavformat/swfdec.c
index e427998744..7a74fa3ac7 100644
--- a/libavformat/swfdec.c
+++ b/libavformat/swfdec.c
@@ -146,13 +146,18 @@  static int swf_read_header(AVFormatContext *s)
         swf->zbuf_out = av_malloc(ZBUF_SIZE);
         swf->zpb = avio_alloc_context(swf->zbuf_out, ZBUF_SIZE, 0, s,
                                       zlib_refill, NULL, NULL);
-        if (!swf->zbuf_in || !swf->zbuf_out || !swf->zpb)
+        if (!swf->zbuf_in || !swf->zbuf_out || !swf->zpb) {
+            av_freep(&swf->zbuf_in);
+            av_freep(&swf->zbuf_out);
+            avio_context_free(&swf->zpb);
             return AVERROR(ENOMEM);
+        }
         swf->zpb->seekable = 0;
         if (inflateInit(&swf->zstream) != Z_OK) {
             av_log(s, AV_LOG_ERROR, "Unable to init zlib context\n");
             av_freep(&swf->zbuf_in);
             av_freep(&swf->zbuf_out);
+            avio_context_free(&swf->zpb);
             return AVERROR(EINVAL);
         }
         pb = swf->zpb;