diff mbox series

[FFmpeg-devel,19/54] avformat/libopenmpt: Simplify cleanup after read_header failure

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

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.

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

Patch

diff --git a/libavformat/libopenmpt.c b/libavformat/libopenmpt.c
index 628b0939dc..d04aec5471 100644
--- a/libavformat/libopenmpt.c
+++ b/libavformat/libopenmpt.c
@@ -122,7 +122,6 @@  static int read_header_openmpt(AVFormatContext *s)
     openmpt->channels = av_get_channel_layout_nb_channels(openmpt->layout);
 
     if (openmpt->subsong >= openmpt_module_get_num_subsongs(openmpt->module)) {
-        openmpt_module_destroy(openmpt->module);
         av_log(s, AV_LOG_ERROR, "Invalid subsong index: %d\n", openmpt->subsong);
         return AVERROR(EINVAL);
     }
@@ -133,7 +132,6 @@  static int read_header_openmpt(AVFormatContext *s)
         }
         ret = openmpt_module_select_subsong(openmpt->module, openmpt->subsong);
         if (!ret){
-            openmpt_module_destroy(openmpt->module);
             av_log(s, AV_LOG_ERROR, "Could not select requested subsong: %d", openmpt->subsong);
             return AVERROR(EINVAL);
         }
@@ -148,11 +146,8 @@  static int read_header_openmpt(AVFormatContext *s)
     add_meta(s, "date",    openmpt_module_get_metadata(openmpt->module, "date"));
 
     st = avformat_new_stream(s, NULL);
-    if (!st) {
-        openmpt_module_destroy(openmpt->module);
-        openmpt->module = NULL;
+    if (!st)
         return AVERROR(ENOMEM);
-    }
     avpriv_set_pts_info(st, 64, 1, AV_TIME_BASE);
     st->duration = llrint(openmpt->duration*AV_TIME_BASE);
 
@@ -206,8 +201,10 @@  static int read_packet_openmpt(AVFormatContext *s, AVPacket *pkt)
 static int read_close_openmpt(AVFormatContext *s)
 {
     OpenMPTContext *openmpt = s->priv_data;
-    openmpt_module_destroy(openmpt->module);
-    openmpt->module = NULL;
+    if (openmpt->module) {
+        openmpt_module_destroy(openmpt->module);
+        openmpt->module = NULL;
+    }
     return 0;
 }
 
@@ -285,6 +282,7 @@  const AVInputFormat ff_libopenmpt_demuxer = {
     .name           = "libopenmpt",
     .long_name      = NULL_IF_CONFIG_SMALL("Tracker formats (libopenmpt)"),
     .priv_data_size = sizeof(OpenMPTContext),
+    .flags_internal = FF_FMT_INIT_CLEANUP,
     .read_probe     = read_probe_openmpt,
     .read_header    = read_header_openmpt,
     .read_packet    = read_packet_openmpt,