avformat/ape: 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:
Andreas Rheinhardt 2020-03-21 18:31:06 +01:00
parent 609672a4a3
commit 58da6b18a3

View File

@ -79,8 +79,6 @@ typedef struct APEContext {
uint32_t samplerate; uint32_t samplerate;
} APEContext; } APEContext;
static int ape_read_close(AVFormatContext * s);
static int ape_probe(const AVProbeData * p) static int ape_probe(const AVProbeData * p)
{ {
int version = AV_RL16(p->buf+4); int version = AV_RL16(p->buf+4);
@ -276,8 +274,7 @@ static int ape_read_header(AVFormatContext * s)
if (pb->eof_reached) { if (pb->eof_reached) {
av_log(s, AV_LOG_ERROR, "seektable truncated\n"); av_log(s, AV_LOG_ERROR, "seektable truncated\n");
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto fail;
} }
ff_dlog(s, "seektable: %8d %"PRIu32"\n", i, seektable_entry); ff_dlog(s, "seektable: %8d %"PRIu32"\n", i, seektable_entry);
} }
@ -313,8 +310,7 @@ static int ape_read_header(AVFormatContext * s)
ff_dlog(s, "bittable: %2d\n", bits); ff_dlog(s, "bittable: %2d\n", bits);
if (pb->eof_reached) { if (pb->eof_reached) {
av_log(s, AV_LOG_ERROR, "bittable truncated\n"); av_log(s, AV_LOG_ERROR, "bittable truncated\n");
ret = AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
goto fail;
} }
} }
} }
@ -327,10 +323,8 @@ static int ape_read_header(AVFormatContext * s)
/* now we are ready: build format streams */ /* now we are ready: build format streams */
st = avformat_new_stream(s, NULL); st = avformat_new_stream(s, NULL);
if (!st) { if (!st)
ret = AVERROR(ENOMEM); return AVERROR(ENOMEM);
goto fail;
}
total_blocks = (ape->totalframes == 0) ? 0 : ((ape->totalframes - 1) * ape->blocksperframe) + ape->finalframeblocks; total_blocks = (ape->totalframes == 0) ? 0 : ((ape->totalframes - 1) * ape->blocksperframe) + ape->finalframeblocks;
@ -347,7 +341,7 @@ static int ape_read_header(AVFormatContext * s)
avpriv_set_pts_info(st, 64, 1, ape->samplerate); avpriv_set_pts_info(st, 64, 1, ape->samplerate);
if ((ret = ff_alloc_extradata(st->codecpar, APE_EXTRADATA_SIZE)) < 0) if ((ret = ff_alloc_extradata(st->codecpar, APE_EXTRADATA_SIZE)) < 0)
goto fail; return ret;
AV_WL16(st->codecpar->extradata + 0, ape->fileversion); AV_WL16(st->codecpar->extradata + 0, ape->fileversion);
AV_WL16(st->codecpar->extradata + 2, ape->compressiontype); AV_WL16(st->codecpar->extradata + 2, ape->compressiontype);
AV_WL16(st->codecpar->extradata + 4, ape->formatflags); AV_WL16(st->codecpar->extradata + 4, ape->formatflags);
@ -366,10 +360,6 @@ static int ape_read_header(AVFormatContext * s)
} }
return 0; return 0;
fail:
ape_read_close(s);
return ret;
} }
static int ape_read_packet(AVFormatContext * s, AVPacket * pkt) static int ape_read_packet(AVFormatContext * s, AVPacket * pkt)
@ -454,6 +444,7 @@ const AVInputFormat ff_ape_demuxer = {
.name = "ape", .name = "ape",
.long_name = NULL_IF_CONFIG_SMALL("Monkey's Audio"), .long_name = NULL_IF_CONFIG_SMALL("Monkey's Audio"),
.priv_data_size = sizeof(APEContext), .priv_data_size = sizeof(APEContext),
.flags_internal = FF_FMT_INIT_CLEANUP,
.read_probe = ape_probe, .read_probe = ape_probe,
.read_header = ape_read_header, .read_header = ape_read_header,
.read_packet = ape_read_packet, .read_packet = ape_read_packet,