History

avformat/avidec: Fix memleak when error happens after creating DV stream

Andreas Rheinhardt committed 6 years ago

Commit ea45d6e1 parent c7867b61 file · +17 −14Browse files

Unified · Split

libavformat/avidec.c+17−14
@@ -113,6 +113,7 @@ static const AVMetadataConv avi_metadata_conv[] = { · 112 unmodified lines
113113 { 0 },
114114 };
115115
116+static int avi_read_close(AVFormatContext *s);
116117 static int avi_load_index(AVFormatContext *s);
117118 static int guess_ni_flag(AVFormatContext *s);
118119
@@ -464,6 +465,7 @@ static int calculate_bitrate(AVFormatContext *s) · 345 unmodified lines
464465 return 1;
465466 }
466467
468+#define RETURN_ERROR(code) do { ret = (code); goto fail; } while (0)
467469 static int avi_read_header(AVFormatContext *s)
468470 {
469471 AVIContext *avi = s->priv_data;
@@ -499,7 +501,7 @@ static int avi_read_header(AVFormatContext *s) · 29 unmodified lines
499501 frame_period = 0;
500502 for (;;) {
501503 if (avio_feof(pb))
502− goto fail;
504+ RETURN_ERROR(AVERROR_INVALIDDATA);
503505 tag = avio_rl32(pb);
504506 size = avio_rl32(pb);
505507
@@ -571,12 +573,12 @@ static int avi_read_header(AVFormatContext *s) · 65 unmodified lines
571573 stream_index++;
572574 st = avformat_new_stream(s, NULL);
573575 if (!st)
574− goto fail;
576+ RETURN_ERROR(AVERROR(ENOMEM));
575577
576578 st->id = stream_index;
577579 ast = av_mallocz(sizeof(AVIStream));
578580 if (!ast)
579− goto fail;
581+ RETURN_ERROR(AVERROR(ENOMEM));
580582 st->priv_data = ast;
581583 }
582584 if (amv_file_format)
@@ -592,12 +594,12 @@ static int avi_read_header(AVFormatContext *s) · 9 unmodified lines
592594 /* After some consideration -- I don't think we
593595 * have to support anything but DV in type1 AVIs. */
594596 if (s->nb_streams != 1)
595− goto fail;
597+ RETURN_ERROR(AVERROR_INVALIDDATA);
596598
597599 if (handler != MKTAG('d', 'v', 's', 'd') &&
598600 handler != MKTAG('d', 'v', 'h', 'd') &&
599601 handler != MKTAG('d', 'v', 's', 'l'))
600− goto fail;
602+ return AVERROR_INVALIDDATA;
601603
602604 if (!CONFIG_DV_DEMUXER)
603605 return AVERROR_DEMUXER_NOT_FOUND;
@@ -697,7 +699,7 @@ static int avi_read_header(AVFormatContext *s) · 93 unmodified lines
697699 "Invalid sample_size %d at stream %d\n",
698700 ast->sample_size,
699701 stream_index);
700− goto fail;
702+ RETURN_ERROR(AVERROR_INVALIDDATA);
701703 }
702704 av_log(s, AV_LOG_WARNING,
703705 "Invalid sample_size %d at stream %d "
@@ -927,7 +929,7 @@ static int avi_read_header(AVFormatContext *s) · 223 unmodified lines
927929 av_log(s, AV_LOG_WARNING, "New extradata in strd chunk, freeing previous one.\n");
928930 }
929931 if ((ret = ff_get_extradata(s, st->codecpar, pb, size)) < 0)
930− return ret;
932+ goto fail;
931933 }
932934
933935 if (st->codecpar->extradata_size & 1) //FIXME check if the encoder really did this correctly
@@ -945,7 +947,7 @@ static int avi_read_header(AVFormatContext *s) · 11 unmodified lines
945947 avi->use_odml &&
946948 read_odml_index(s, 0) < 0 &&
947949 (s->error_recognition & AV_EF_EXPLODE))
948− goto fail;
950+ RETURN_ERROR(AVERROR_INVALIDDATA);
949951 avio_seek(pb, pos + size, SEEK_SET);
950952 break;
951953 case MKTAG('v', 'p', 'r', 'p'):
@@ -980,7 +982,7 @@ static int avi_read_header(AVFormatContext *s) · 28 unmodified lines
980982 if (s->nb_streams) {
981983 ret = avi_read_tag(s, s->streams[s->nb_streams - 1], tag, size);
982984 if (ret < 0)
983− return ret;
985+ goto fail;
984986 break;
985987 }
986988 default:
@@ -991,7 +993,7 @@ static int avi_read_header(AVFormatContext *s) · 4 unmodified lines
991993 "I will ignore it and try to continue anyway.\n",
992994 av_fourcc2str(tag), size);
993995 if (s->error_recognition & AV_EF_EXPLODE)
994− goto fail;
996+ RETURN_ERROR(AVERROR_INVALIDDATA);
995997 avi->movi_list = avio_tell(pb) - 4;
996998 avi->movi_end = avi->fsize;
997999 goto end_of_header;
@@ -1008,9 +1010,7 @@ static int avi_read_header(AVFormatContext *s) · 10 unmodified lines
10081010 end_of_header:
10091011 /* check stream number */
10101012 if (stream_index != s->nb_streams - 1) {
1011−
1012−fail:
1013− return AVERROR_INVALIDDATA;
1013+ RETURN_ERROR(AVERROR_INVALIDDATA);
10141014 }
10151015
10161016 if (!avi->index_loaded && (pb->seekable & AVIO_SEEKABLE_NORMAL))
@@ -1019,7 +1019,7 @@ fail: · 2 unmodified lines
10191019 avi->index_loaded |= 1;
10201020
10211021 if ((ret = guess_ni_flag(s)) < 0)
1022− return ret;
1022+ goto fail;
10231023
10241024 avi->non_interleaved |= ret | (s->flags & AVFMT_FLAG_SORT_DTS);
10251025
@@ -1056,6 +1056,9 @@ fail: · 30 unmodified lines
10561056 ff_metadata_conv_ctx(s, NULL, ff_riff_info_conv);
10571057
10581058 return 0;
1059+fail:
1060+ avi_read_close(s);
1061+ return ret;
10591062 }
10601063
10611064 static int read_gab2_sub(AVFormatContext *s, AVStream *st, AVPacket *pkt)

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