aboutsummaryrefslogtreecommitdiffstats
path: root/fftools
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-10-07 01:51:30 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2023-10-10 14:30:07 +0200
commitc06d3d24047206f9c11bfc5849544b960e5d68eb (patch)
treeb79e072175f13a4e90da7b75fa7c3ce436c222e0 /fftools
parentd98dfcecad179260182d90ed1d170c1037db7568 (diff)
downloadffmpeg-c06d3d24047206f9c11bfc5849544b960e5d68eb.tar.gz
fftools/ffmpeg_demux: Fix leak on error
An AVFormatContext leaks on errors that happen before it is attached to its permanent place (an InputFile). Fix this by attaching it earlier. Given that it is not documented that avformat_close_input() is usable with an AVFormatContext that has only been allocated with avformat_alloc_context() and not opened with avformat_open_input(), one error path before avformat_open_input() had to be treated specially: It uses avformat_free_context(). Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'fftools')
-rw-r--r--fftools/ffmpeg_demux.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 41fcb678c6..350f233ab7 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -1462,8 +1462,10 @@ int ifile_open(const OptionsContext *o, const char *filename)
if (data_codec_name)
ret = err_merge(ret, find_codec(NULL, data_codec_name , AVMEDIA_TYPE_DATA, 0,
&ic->data_codec));
- if (ret < 0)
+ if (ret < 0) {
+ avformat_free_context(ic);
return ret;
+ }
ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE;
ic->audio_codec_id = audio_codec_name ? ic->audio_codec->id : AV_CODEC_ID_NONE;
@@ -1488,6 +1490,7 @@ int ifile_open(const OptionsContext *o, const char *filename)
av_log(d, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
return err;
}
+ f->ctx = ic;
av_strlcat(d->log_name, "/", sizeof(d->log_name));
av_strlcat(d->log_name, ic->iformat->name, sizeof(d->log_name));
@@ -1527,10 +1530,8 @@ int ifile_open(const OptionsContext *o, const char *filename)
if (ret < 0) {
av_log(d, AV_LOG_FATAL, "could not find codec parameters\n");
- if (ic->nb_streams == 0) {
- avformat_close_input(&ic);
+ if (ic->nb_streams == 0)
return ret;
- }
}
}
@@ -1582,7 +1583,6 @@ int ifile_open(const OptionsContext *o, const char *filename)
}
}
- f->ctx = ic;
f->start_time = start_time;
f->recording_time = recording_time;
f->input_sync_ref = o->input_sync_ref;