diff mbox

[FFmpeg-devel,3/3] avformat/mpeg: Fix leaks of AVFormatContext and subtitle packets

Message ID 20191204123714.27765-3-andreas.rheinhardt@gmail.com
State Accepted
Commit 4825d8a98d4cddab8710055213e99e47cfd5257a
Headers show

Commit Message

Andreas Rheinhardt Dec. 4, 2019, 12:37 p.m. UTC
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>
---
Supersedes https://ffmpeg.org/pipermail/ffmpeg-devel/2019-October/252075.html
Resending because of merge conflicts.

 libavformat/mpeg.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

Comments

Michael Niedermayer Dec. 5, 2019, 7:18 p.m. UTC | #1
On Wed, Dec 04, 2019 at 01:37:14PM +0100, 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>
> ---
> Supersedes https://ffmpeg.org/pipermail/ffmpeg-devel/2019-October/252075.html
> Resending because of merge conflicts.

will apply

thx

[...]
diff mbox

Patch

diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index e4fe16c7d2..e61851bba5 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -713,6 +713,18 @@  static int vobsub_probe(const AVProbeData *p)
     return 0;
 }
 
+static int vobsub_read_close(AVFormatContext *s)
+{
+    VobSubDemuxContext *vobsub = s->priv_data;
+    int i;
+
+    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;
@@ -896,7 +908,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;
 }
@@ -1021,18 +1034,6 @@  static int vobsub_read_seek(AVFormatContext *s, int stream_index,
                                    min_ts, ts, max_ts, flags);
 }
 
-static int vobsub_read_close(AVFormatContext *s)
-{
-    VobSubDemuxContext *vobsub = s->priv_data;
-    int i;
-
-    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(VobSubDemuxContext, sub_name), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
     { NULL }