avformat/avidec: Fix memleak when allocating DVDemuxContext fails
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Fri, 27 Mar 2020 04:31:13 +0000 (05:31 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sun, 5 Apr 2020 16:30:50 +0000 (18:30 +0200)
An AVIStream (intended to be used as private data for an AVStream) would
leak in this scenario.

Also return a more fitting error code instead of AVERROR_INVALIDDATA.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavformat/avidec.c

index 18402f0..8729851 100644 (file)
@@ -605,9 +605,12 @@ static int avi_read_header(AVFormatContext *s)
                 ast = s->streams[0]->priv_data;
                 st->priv_data = NULL;
                 ff_free_stream(s, st);
-                    avi->dv_demux = avpriv_dv_init_demux(s);
-                    if (!avi->dv_demux)
-                        goto fail;
+
+                avi->dv_demux = avpriv_dv_init_demux(s);
+                if (!avi->dv_demux) {
+                    av_free(ast);
+                    return AVERROR(ENOMEM);
+                }
 
                 s->streams[0]->priv_data = ast;
                 avio_skip(pb, 3 * 4);