diff mbox series

[FFmpeg-devel,2/4] avformat/avidec: Fix memleak when DV demuxer is disabled

Message ID 20200327095557.24069-2-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,1/4] avformat/avidec: Don't reimplement ff_free_stream() | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Andreas Rheinhardt March 27, 2020, 9:55 a.m. UTC
If one uses a build without dv demuxer, an AVIStream struct that is
destined to be used as private data for an AVStream by the avi demuxer
would leak, because it has been moved from the AVStream (that is going
to be freed) and only stored in a local variable (in order to be used
for another AVStream), but if the dv demuxer is disabled, the earlier
code returned immediately instead.

Also return a better error code in this scenario (instead of
AVERROR_INVALIDDATA).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
Like lots of other parts of the code, this also relies on the compiler's
ability to eliminate dead code; otherwise linking would fail because
avpriv_dv_init_demux would not be available.

 libavformat/avidec.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/avidec.c b/libavformat/avidec.c
index ae343e732a..18402f0032 100644
--- a/libavformat/avidec.c
+++ b/libavformat/avidec.c
@@ -599,15 +599,16 @@  static int avi_read_header(AVFormatContext *s)
                     handler != MKTAG('d', 'v', 's', 'l'))
                     goto fail;
 
+                if (!CONFIG_DV_DEMUXER)
+                    return AVERROR_DEMUXER_NOT_FOUND;
+
                 ast = s->streams[0]->priv_data;
                 st->priv_data = NULL;
                 ff_free_stream(s, st);
-                if (CONFIG_DV_DEMUXER) {
                     avi->dv_demux = avpriv_dv_init_demux(s);
                     if (!avi->dv_demux)
                         goto fail;
-                } else
-                    goto fail;
+
                 s->streams[0]->priv_data = ast;
                 avio_skip(pb, 3 * 4);
                 ast->scale = avio_rl32(pb);