mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
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>
This commit is contained in:
parent
d98dfcecad
commit
c06d3d2404
@ -1462,8 +1462,10 @@ int ifile_open(const OptionsContext *o, const char *filename)
|
|||||||
if (data_codec_name)
|
if (data_codec_name)
|
||||||
ret = err_merge(ret, find_codec(NULL, data_codec_name , AVMEDIA_TYPE_DATA, 0,
|
ret = err_merge(ret, find_codec(NULL, data_codec_name , AVMEDIA_TYPE_DATA, 0,
|
||||||
&ic->data_codec));
|
&ic->data_codec));
|
||||||
if (ret < 0)
|
if (ret < 0) {
|
||||||
|
avformat_free_context(ic);
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
ic->video_codec_id = video_codec_name ? ic->video_codec->id : AV_CODEC_ID_NONE;
|
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;
|
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);
|
av_log(d, AV_LOG_ERROR, "Did you mean file:%s?\n", filename);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
f->ctx = ic;
|
||||||
|
|
||||||
av_strlcat(d->log_name, "/", sizeof(d->log_name));
|
av_strlcat(d->log_name, "/", sizeof(d->log_name));
|
||||||
av_strlcat(d->log_name, ic->iformat->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) {
|
if (ret < 0) {
|
||||||
av_log(d, AV_LOG_FATAL, "could not find codec parameters\n");
|
av_log(d, AV_LOG_FATAL, "could not find codec parameters\n");
|
||||||
if (ic->nb_streams == 0) {
|
if (ic->nb_streams == 0)
|
||||||
avformat_close_input(&ic);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1582,7 +1583,6 @@ int ifile_open(const OptionsContext *o, const char *filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f->ctx = ic;
|
|
||||||
f->start_time = start_time;
|
f->start_time = start_time;
|
||||||
f->recording_time = recording_time;
|
f->recording_time = recording_time;
|
||||||
f->input_sync_ref = o->input_sync_ref;
|
f->input_sync_ref = o->input_sync_ref;
|
||||||
|
Loading…
Reference in New Issue
Block a user