avformat/libgme: Simplify cleanup after read_header failure
by setting the FF_FMT_INIT_CLEANUP flag. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
0d00167b7e
commit
87319ed26f
|
@ -84,7 +84,8 @@ static int load_metadata(AVFormatContext *s, int64_t *duration)
|
||||||
static int read_close_gme(AVFormatContext *s)
|
static int read_close_gme(AVFormatContext *s)
|
||||||
{
|
{
|
||||||
GMEContext *gme = s->priv_data;
|
GMEContext *gme = s->priv_data;
|
||||||
gme_delete(gme->music_emu);
|
if (gme->music_emu)
|
||||||
|
gme_delete(gme->music_emu);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,26 +122,21 @@ static int read_header_gme(AVFormatContext *s)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gme_open_data(buf, sz, &gme->music_emu, gme->sample_rate)) {
|
if (gme_open_data(buf, sz, &gme->music_emu, gme->sample_rate)) {
|
||||||
|
gme->music_emu = NULL; /* Just for safety */
|
||||||
av_freep(&buf);
|
av_freep(&buf);
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
}
|
}
|
||||||
av_freep(&buf);
|
av_freep(&buf);
|
||||||
|
|
||||||
ret = load_metadata(s, &duration);
|
ret = load_metadata(s, &duration);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
read_close_gme(s);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
if (gme_start_track(gme->music_emu, gme->track_index))
|
||||||
if (gme_start_track(gme->music_emu, gme->track_index)) {
|
|
||||||
read_close_gme(s);
|
|
||||||
return AVERROR_UNKNOWN;
|
return AVERROR_UNKNOWN;
|
||||||
}
|
|
||||||
|
|
||||||
st = avformat_new_stream(s, NULL);
|
st = avformat_new_stream(s, NULL);
|
||||||
if (!st) {
|
if (!st)
|
||||||
read_close_gme(s);
|
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
}
|
|
||||||
avpriv_set_pts_info(st, 64, 1, 1000);
|
avpriv_set_pts_info(st, 64, 1, 1000);
|
||||||
if (duration > 0)
|
if (duration > 0)
|
||||||
st->duration = duration;
|
st->duration = duration;
|
||||||
|
@ -201,6 +197,7 @@ const AVInputFormat ff_libgme_demuxer = {
|
||||||
.name = "libgme",
|
.name = "libgme",
|
||||||
.long_name = NULL_IF_CONFIG_SMALL("Game Music Emu demuxer"),
|
.long_name = NULL_IF_CONFIG_SMALL("Game Music Emu demuxer"),
|
||||||
.priv_data_size = sizeof(GMEContext),
|
.priv_data_size = sizeof(GMEContext),
|
||||||
|
.flags_internal = FF_FMT_INIT_CLEANUP,
|
||||||
.read_probe = probe_gme,
|
.read_probe = probe_gme,
|
||||||
.read_header = read_header_gme,
|
.read_header = read_header_gme,
|
||||||
.read_packet = read_packet_gme,
|
.read_packet = read_packet_gme,
|
||||||
|
|
Loading…
Reference in New Issue