From 82d61a9ce3e26cb950709689f537ad1fdfa830b3 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Wed, 11 Dec 2019 12:21:07 +0100 Subject: [PATCH] avformat: Don't free old extradata before ff_alloc/get_extradata These functions already free it themselves before they allocate the new extradata. Signed-off-by: Andreas Rheinhardt Signed-off-by: Michael Niedermayer --- libavformat/avidec.c | 2 -- libavformat/cafdec.c | 7 ++----- libavformat/concatdec.c | 4 ---- libavformat/flic.c | 1 - libavformat/flvdec.c | 1 - libavformat/matroskaenc.c | 1 - libavformat/mov.c | 4 ---- libavformat/nuv.c | 4 ---- libavformat/oggparseogm.c | 1 - libavformat/oggparseopus.c | 1 - libavformat/riffdec.c | 2 -- libavformat/rtpdec_latm.c | 1 - libavformat/rtpdec_mpeg4.c | 2 +- libavformat/rtpdec_qdm2.c | 2 +- libavformat/rtpdec_svq3.c | 4 ---- libavformat/utils.c | 1 - libavformat/wavdec.c | 1 - libavformat/xmv.c | 2 -- 18 files changed, 4 insertions(+), 37 deletions(-) diff --git a/libavformat/avidec.c b/libavformat/avidec.c index 21871feb8d..ae0c227bb9 100644 --- a/libavformat/avidec.c +++ b/libavformat/avidec.c @@ -770,7 +770,6 @@ FF_ENABLE_DEPRECATION_WARNINGS st->codecpar->extradata_size = size - 10 * 4; if (st->codecpar->extradata) { av_log(s, AV_LOG_WARNING, "New extradata in strf chunk, freeing previous one.\n"); - av_freep(&st->codecpar->extradata); } ret = ff_get_extradata(s, st->codecpar, pb, st->codecpar->extradata_size); @@ -932,7 +931,6 @@ FF_ENABLE_DEPRECATION_WARNINGS if (size<(1<<30)) { if (st->codecpar->extradata) { av_log(s, AV_LOG_WARNING, "New extradata in strd chunk, freeing previous one.\n"); - av_freep(&st->codecpar->extradata); } if ((ret = ff_get_extradata(s, st->codecpar, pb, size)) < 0) return ret; diff --git a/libavformat/cafdec.c b/libavformat/cafdec.c index 85356ec439..d0f942f3e4 100644 --- a/libavformat/cafdec.c +++ b/libavformat/cafdec.c @@ -135,7 +135,6 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size) return AVERROR_INVALIDDATA; } - av_freep(&st->codecpar->extradata); if ((ret = ff_alloc_extradata(st->codecpar, ALAC_HEADER)) < 0) return ret; @@ -175,10 +174,8 @@ static int read_kuki_chunk(AVFormatContext *s, int64_t size) return AVERROR_PATCHWELCOME; } avio_skip(pb, size); - } else { - av_freep(&st->codecpar->extradata); - if ((ret = ff_get_extradata(s, st->codecpar, pb, size)) < 0) - return ret; + } else if ((ret = ff_get_extradata(s, st->codecpar, pb, size)) < 0) { + return ret; } return 0; diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c index b80294efbf..e826821241 100644 --- a/libavformat/concatdec.c +++ b/libavformat/concatdec.c @@ -171,10 +171,6 @@ static int copy_stream_props(AVStream *st, AVStream *source_st) if (st->codecpar->codec_id || !source_st->codecpar->codec_id) { if (st->codecpar->extradata_size < source_st->codecpar->extradata_size) { - if (st->codecpar->extradata) { - av_freep(&st->codecpar->extradata); - st->codecpar->extradata_size = 0; - } ret = ff_alloc_extradata(st->codecpar, source_st->codecpar->extradata_size); if (ret < 0) diff --git a/libavformat/flic.c b/libavformat/flic.c index 4ba72fb037..615d6b25c5 100644 --- a/libavformat/flic.c +++ b/libavformat/flic.c @@ -175,7 +175,6 @@ static int flic_read_header(AVFormatContext *s) avio_seek(pb, 12, SEEK_SET); /* send over abbreviated FLIC header chunk */ - av_freep(&st->codecpar->extradata); if ((ret = ff_alloc_extradata(st->codecpar, 12)) < 0) return ret; memcpy(st->codecpar->extradata, header, 12); diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c index 03b0c22f9d..7c3e5b06c6 100644 --- a/libavformat/flvdec.c +++ b/libavformat/flvdec.c @@ -799,7 +799,6 @@ static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size) if (!size) return 0; - av_freep(&st->codecpar->extradata); if ((ret = ff_get_extradata(s, st->codecpar, s->pb, size)) < 0) return ret; st->internal->need_context_update = 1; diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 570f361351..469b604de6 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -2264,7 +2264,6 @@ static int mkv_check_new_extra_data(AVFormatContext *s, AVPacket *pkt) return ret; if (!output_sample_rate) output_sample_rate = track->sample_rate; // Space is already reserved, so it's this or a void element. - av_freep(&par->extradata); ret = ff_alloc_extradata(par, side_data_size); if (ret < 0) return ret; diff --git a/libavformat/mov.c b/libavformat/mov.c index dd903f71a0..890c6e85b8 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -1838,7 +1838,6 @@ static int mov_read_wave(MOVContext *c, AVIOContext *pb, MOVAtom atom) st->codecpar->codec_id == AV_CODEC_ID_QDMC || st->codecpar->codec_id == AV_CODEC_ID_SPEEX) { // pass all frma atom to codec, needed at least for QDMC and QDM2 - av_freep(&st->codecpar->extradata); ret = ff_get_extradata(c->fc, st->codecpar, pb, atom.size); if (ret < 0) return ret; @@ -1905,7 +1904,6 @@ static int mov_read_glbl(MOVContext *c, AVIOContext *pb, MOVAtom atom) av_log(c->fc, AV_LOG_WARNING, "ignoring multiple glbl\n"); return 0; } - av_freep(&st->codecpar->extradata); ret = ff_get_extradata(c->fc, st->codecpar, pb, atom.size); if (ret < 0) return ret; @@ -1938,7 +1936,6 @@ static int mov_read_dvc1(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; avio_seek(pb, 6, SEEK_CUR); - av_freep(&st->codecpar->extradata); ret = ff_get_extradata(c->fc, st->codecpar, pb, atom.size - 7); if (ret < 0) return ret; @@ -1966,7 +1963,6 @@ static int mov_read_strf(MOVContext *c, AVIOContext *pb, MOVAtom atom) return AVERROR_INVALIDDATA; avio_skip(pb, 40); - av_freep(&st->codecpar->extradata); ret = ff_get_extradata(c->fc, st->codecpar, pb, atom.size - 40); if (ret < 0) return ret; diff --git a/libavformat/nuv.c b/libavformat/nuv.c index 612f845b4b..bef0ae4860 100644 --- a/libavformat/nuv.c +++ b/libavformat/nuv.c @@ -83,10 +83,6 @@ static int get_codec_data(AVFormatContext *s, AVIOContext *pb, AVStream *vst, avio_skip(pb, 6); size = PKTSIZE(avio_rl32(pb)); if (vst && subtype == 'R') { - if (vst->codecpar->extradata) { - av_freep(&vst->codecpar->extradata); - vst->codecpar->extradata_size = 0; - } if ((ret = ff_get_extradata(NULL, vst->codecpar, pb, size)) < 0) return ret; size = 0; diff --git a/libavformat/oggparseogm.c b/libavformat/oggparseogm.c index f25efb8c2a..469b229995 100644 --- a/libavformat/oggparseogm.c +++ b/libavformat/oggparseogm.c @@ -109,7 +109,6 @@ ogm_header(AVFormatContext *s, int idx) size -= 52; if (bytestream2_get_bytes_left(&p) < size) return AVERROR_INVALIDDATA; - av_freep(&st->codecpar->extradata); if ((ret = ff_alloc_extradata(st->codecpar, size)) < 0) return ret; bytestream2_get_buffer(&p, st->codecpar->extradata, st->codecpar->extradata_size); diff --git a/libavformat/oggparseopus.c b/libavformat/oggparseopus.c index 38908dc2dd..56b53e74e8 100644 --- a/libavformat/oggparseopus.c +++ b/libavformat/oggparseopus.c @@ -63,7 +63,6 @@ static int opus_header(AVFormatContext *avf, int idx) /*gain = AV_RL16(packet + 16);*/ /*channel_map = AV_RL8 (packet + 18);*/ - av_freep(&st->codecpar->extradata); if ((ret = ff_alloc_extradata(st->codecpar, os->psize)) < 0) return ret; diff --git a/libavformat/riffdec.c b/libavformat/riffdec.c index 5523b31adc..070c42eee3 100644 --- a/libavformat/riffdec.c +++ b/libavformat/riffdec.c @@ -145,7 +145,6 @@ int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, size -= 22; } if (cbSize > 0) { - av_freep(&par->extradata); if (ff_get_extradata(s, par, pb, cbSize) < 0) return AVERROR(ENOMEM); size -= cbSize; @@ -158,7 +157,6 @@ int ff_get_wav_header(AVFormatContext *s, AVIOContext *pb, int nb_streams, i; size -= 4; - av_freep(&par->extradata); if (ff_get_extradata(s, par, pb, size) < 0) return AVERROR(ENOMEM); nb_streams = AV_RL16(par->extradata + 4); diff --git a/libavformat/rtpdec_latm.c b/libavformat/rtpdec_latm.c index de18e81ea9..104a00af18 100644 --- a/libavformat/rtpdec_latm.c +++ b/libavformat/rtpdec_latm.c @@ -115,7 +115,6 @@ static int parse_fmtp_config(AVStream *st, const char *value) ret = AVERROR_PATCHWELCOME; goto end; } - av_freep(&st->codecpar->extradata); ret = ff_alloc_extradata(st->codecpar, (get_bits_left(&gb) + 7)/8); if (ret < 0) { goto end; diff --git a/libavformat/rtpdec_mpeg4.c b/libavformat/rtpdec_mpeg4.c index 45569c18d1..34c7950bcc 100644 --- a/libavformat/rtpdec_mpeg4.c +++ b/libavformat/rtpdec_mpeg4.c @@ -113,7 +113,7 @@ static int parse_fmtp_config(AVCodecParameters *par, const char *value) { /* decode the hexa encoded parameter */ int len = ff_hex_to_data(NULL, value), ret; - av_freep(&par->extradata); + if ((ret = ff_alloc_extradata(par, len)) < 0) return ret; ff_hex_to_data(par->extradata, value); diff --git a/libavformat/rtpdec_qdm2.c b/libavformat/rtpdec_qdm2.c index a6a746becb..1eec2da5b4 100644 --- a/libavformat/rtpdec_qdm2.c +++ b/libavformat/rtpdec_qdm2.c @@ -105,7 +105,7 @@ static int qdm2_parse_config(PayloadContext *qdm, AVStream *st, case 4: /* stream with extradata */ if (item_len < 30) return AVERROR_INVALIDDATA; - av_freep(&st->codecpar->extradata); + ret = ff_alloc_extradata(st->codecpar, 26 + item_len); if (ret < 0) { return ret; diff --git a/libavformat/rtpdec_svq3.c b/libavformat/rtpdec_svq3.c index 77164dd6f9..ffe21ac4c4 100644 --- a/libavformat/rtpdec_svq3.c +++ b/libavformat/rtpdec_svq3.c @@ -58,10 +58,6 @@ static int svq3_parse_packet (AVFormatContext *s, PayloadContext *sv, len -= 2; if (config_packet) { - - av_freep(&st->codecpar->extradata); - st->codecpar->extradata_size = 0; - if (len < 2 || ff_alloc_extradata(st->codecpar, len + 8)) return AVERROR_INVALIDDATA; diff --git a/libavformat/utils.c b/libavformat/utils.c index 2d772b25a8..b472762dd1 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -5480,7 +5480,6 @@ int ff_generate_avci_extradata(AVStream *st) if (!size) return 0; - av_freep(&st->codecpar->extradata); if ((ret = ff_alloc_extradata(st->codecpar, size)) < 0) return ret; memcpy(st->codecpar->extradata, data, size); diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c index cfaf3d61fe..575c667452 100644 --- a/libavformat/wavdec.c +++ b/libavformat/wavdec.c @@ -220,7 +220,6 @@ static int wav_parse_xma2_tag(AVFormatContext *s, int64_t size, AVStream **st) avpriv_set_pts_info(*st, 64, 1, (*st)->codecpar->sample_rate); avio_seek(pb, -size, SEEK_CUR); - av_freep(&(*st)->codecpar->extradata); if ((ret = ff_get_extradata(s, (*st)->codecpar, pb, size)) < 0) return ret; diff --git a/libavformat/xmv.c b/libavformat/xmv.c index 7f12956458..0c69d267de 100644 --- a/libavformat/xmv.c +++ b/libavformat/xmv.c @@ -397,8 +397,6 @@ static int xmv_process_packet_header(AVFormatContext *s) av_assert0(xmv->video.stream_index < s->nb_streams); if (vst->codecpar->extradata_size < 4) { - av_freep(&vst->codecpar->extradata); - if ((ret = ff_alloc_extradata(vst->codecpar, 4)) < 0) return ret; }