[FFmpeg-devel,4/5] avformat/mpeg: Fix memleak II

Submitted by Andreas Rheinhardt on Oct. 22, 2019, 1:16 p.m.

Details

Message ID 20191022131645.8394-4-andreas.rheinhardt@gmail.com
State New
Headers show

Commit Message

Andreas Rheinhardt Oct. 22, 2019, 1:16 p.m.
If an error happens in vobsub_read_header() after allocating the
AVFormatContext intended to read the sub-file, both the AVFormatContext
as well as the data in the subtitles queues leaks. This has been fixed.

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

Comments

Michael Niedermayer Oct. 24, 2019, 5:42 p.m.
On Tue, Oct 22, 2019 at 03:16:44PM +0200, Andreas Rheinhardt wrote:
> If an error happens in vobsub_read_header() after allocating the
> AVFormatContext intended to read the sub-file, both the AVFormatContext
> as well as the data in the subtitles queues leaks. This has been fixed.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/mpeg.c | 27 ++++++++++++++-------------
>  1 file changed, 14 insertions(+), 13 deletions(-)

The one line description "memleak II" feels a bit unspecific
"memleak I" "memleak II" "memleak III" tell nothing really

thx

[...]

Patch hide | download patch | download mbox

diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index e6bc6700de..73ade71d95 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -715,6 +715,18 @@  static int vobsub_probe(const AVProbeData *p)
     return 0;
 }
 
+static int vobsub_read_close(AVFormatContext *s)
+{
+    int i;
+    MpegDemuxContext *vobsub = s->priv_data;
+
+    for (i = 0; i < s->nb_streams; i++)
+        ff_subtitles_queue_clean(&vobsub->q[i]);
+    if (vobsub->sub_ctx)
+        avformat_close_input(&vobsub->sub_ctx);
+    return 0;
+}
+
 static int vobsub_read_header(AVFormatContext *s)
 {
     int i, ret = 0, header_parsed = 0, langidx = 0;
@@ -898,7 +910,8 @@  static int vobsub_read_header(AVFormatContext *s)
         memcpy(par->extradata, header.str, header.len);
     }
 end:
-
+    if (ret < 0)
+        vobsub_read_close(s);
     av_bprint_finalize(&header, NULL);
     return ret;
 }
@@ -1023,18 +1036,6 @@  static int vobsub_read_seek(AVFormatContext *s, int stream_index,
                                    min_ts, ts, max_ts, flags);
 }
 
-static int vobsub_read_close(AVFormatContext *s)
-{
-    int i;
-    MpegDemuxContext *vobsub = s->priv_data;
-
-    for (i = 0; i < s->nb_streams; i++)
-        ff_subtitles_queue_clean(&vobsub->q[i]);
-    if (vobsub->sub_ctx)
-        avformat_close_input(&vobsub->sub_ctx);
-    return 0;
-}
-
 static const AVOption options[] = {
     { "sub_name", "URI for .sub file", offsetof(MpegDemuxContext, sub_name), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
     { NULL }