Skip to content

Commit

Permalink
avformat: Don't free old extradata before ff_alloc/get_extradata
Browse files Browse the repository at this point in the history
These functions already free it themselves before they allocate the new
extradata.

Signed-off-by: Andreas Rheinhardt <[email protected]>
Signed-off-by: Michael Niedermayer <[email protected]>
  • Loading branch information
mkver authored and michaelni committed Dec 12, 2019
1 parent c1e439d commit 82d61a9
Show file tree
Hide file tree
Showing 18 changed files with 4 additions and 37 deletions.
2 changes: 0 additions & 2 deletions libavformat/avidec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions libavformat/cafdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions libavformat/concatdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion libavformat/flic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion libavformat/flvdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion libavformat/matroskaenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions libavformat/mov.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions libavformat/nuv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion libavformat/oggparseogm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion libavformat/oggparseopus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 0 additions & 2 deletions libavformat/riffdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion libavformat/rtpdec_latm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libavformat/rtpdec_mpeg4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion libavformat/rtpdec_qdm2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions libavformat/rtpdec_svq3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 0 additions & 1 deletion libavformat/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion libavformat/wavdec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 0 additions & 2 deletions libavformat/xmv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 82d61a9

Please sign in to comment.