diff mbox series

[FFmpeg-devel,26/54] avformat/mpeg: Simplify cleanup after reading vobsub header fails

Message ID HE1PR0301MB2154E58C87B641DD852A47328F309@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit bcdc1d106062677c17e721875b77f8dcae3b2a1a
Headers show
Series [FFmpeg-devel,01/54] avformat: Add internal flags for AV(In|Out)putFormat
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt June 15, 2021, 11:32 p.m. UTC
by setting the FF_FMT_INIT_CLEANUP flag. Furthermore, also remove
an unnecessary check for NULL before avformat_close_input().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/mpeg.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index 178e71d891..4b7493395d 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -723,8 +723,7 @@  static int vobsub_read_close(AVFormatContext *s)
 
     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);
+    avformat_close_input(&vobsub->sub_ctx);
     return 0;
 }
 
@@ -768,17 +767,17 @@  static int vobsub_read_header(AVFormatContext *s)
         return AVERROR(ENOMEM);
     }
 
-    av_bprint_init(&header, 0, INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE);
-
     if ((ret = ff_copy_whiteblacklists(vobsub->sub_ctx, s)) < 0)
-        goto end;
+        return ret;
 
     ret = avformat_open_input(&vobsub->sub_ctx, vobsub->sub_name, iformat, NULL);
     if (ret < 0) {
         av_log(s, AV_LOG_ERROR, "Unable to open %s as MPEG subtitles\n", vobsub->sub_name);
-        goto end;
+        return ret;
     }
 
+    av_bprint_init(&header, 0, INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE);
+
     while (!avio_feof(s->pb)) {
         char line[MAX_LINE_SIZE];
         int len = ff_get_line(s->pb, line, sizeof(line));
@@ -911,8 +910,6 @@  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;
 }
@@ -1044,6 +1041,7 @@  const AVInputFormat ff_vobsub_demuxer = {
     .name           = "vobsub",
     .long_name      = NULL_IF_CONFIG_SMALL("VobSub subtitle format"),
     .priv_data_size = sizeof(VobSubDemuxContext),
+    .flags_internal = FF_FMT_INIT_CLEANUP,
     .read_probe     = vobsub_probe,
     .read_header    = vobsub_read_header,
     .read_packet    = vobsub_read_packet,