History

avformat/flvdec: don't leak extradata pointer on realloc failure

Timo Rothenpieler committed 1 year ago

Commit af74fe71 parent 9201f871 file · +13 −9Browse files

Unified · Split

libavformat/flvdec.c+13−9
@@ -975,18 +975,22 @@ static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream, · 974 unmodified lines
975975 int new_count = stream + 1;
976976
977977 if (flv->mt_extradata_cnt < new_count) {
978− flv->mt_extradata = av_realloc(flv->mt_extradata,
979− sizeof(*flv->mt_extradata) *
980− new_count);
981− flv->mt_extradata_sz = av_realloc(flv->mt_extradata_sz,
982− sizeof(*flv->mt_extradata_sz) *
983− new_count);
984− if (!flv->mt_extradata || !flv->mt_extradata_sz)
978+ void *tmp = av_realloc_array(flv->mt_extradata, new_count,
979+ sizeof(*flv->mt_extradata));
980+ if (!tmp)
985981 return AVERROR(ENOMEM);
982+ flv->mt_extradata = tmp;
983+
984+ tmp = av_realloc_array(flv->mt_extradata_sz, new_count,
985+ sizeof(*flv->mt_extradata_sz));
986+ if (!tmp)
987+ return AVERROR(ENOMEM);
988+ flv->mt_extradata_sz = tmp;
989+
986990 // Set newly allocated pointers/sizes to 0
987991 for (int i = flv->mt_extradata_cnt; i < new_count; i++) {
988− flv->mt_extradata[i] = NULL;
989− flv->mt_extradata_sz[i] = 0;
992+ flv->mt_extradata[i] = NULL;
993+ flv->mt_extradata_sz[i] = 0;
990994 }
991995 flv->mt_extradata_cnt = new_count;
992996 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t