aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-06-14 03:16:15 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-06-15 16:54:05 +0200
commitb12014a5b861959fd41a32ba3ff4cb139c56efcd (patch)
tree44a6d327a719523e7ab9a2970ff05acca05e5f36
parentd38694cea9f289b3f9dcce1a2f07746d029b35f3 (diff)
downloadffmpeg-b12014a5b861959fd41a32ba3ff4cb139c56efcd.tar.gz
avformat/microdvddec: Fix memleak upon read header failure
The already parsed subtitles (contained in an FFDemuxSubtitlesQueue) would leak if an error happened upon reading a subsequent subtitle or when allocating extradata. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
-rw-r--r--libavformat/microdvddec.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/libavformat/microdvddec.c b/libavformat/microdvddec.c
index 08e6fca09c..8759200f88 100644
--- a/libavformat/microdvddec.c
+++ b/libavformat/microdvddec.c
@@ -81,7 +81,7 @@ static int microdvd_read_header(AVFormatContext *s)
AVRational pts_info = (AVRational){ 2997, 125 }; /* default: 23.976 fps */
MicroDVDContext *microdvd = s->priv_data;
AVStream *st = avformat_new_stream(s, NULL);
- int i = 0;
+ int i = 0, ret;
char line_buf[MAX_LINESIZE];
int has_real_fps = 0;
@@ -117,10 +117,10 @@ static int microdvd_read_header(AVFormatContext *s)
continue;
}
if (!st->codecpar->extradata && sscanf(line, "{DEFAULT}{}%c", &c) == 1) {
- int ret, size = strlen(line + 11);
+ int size = strlen(line + 11);
ret = ff_alloc_extradata(st->codecpar, size);
if (ret < 0)
- return ret;
+ goto fail;
memcpy(st->codecpar->extradata, line + 11, size);
continue;
}
@@ -138,8 +138,10 @@ static int microdvd_read_header(AVFormatContext *s)
if (!*p)
continue;
sub = ff_subtitles_queue_insert(&microdvd->q, p, strlen(p), 0);
- if (!sub)
- return AVERROR(ENOMEM);
+ if (!sub) {
+ ret = AVERROR(ENOMEM);
+ goto fail;
+ }
sub->pos = pos;
sub->pts = get_pts(line);
sub->duration = get_duration(line);
@@ -156,6 +158,9 @@ static int microdvd_read_header(AVFormatContext *s)
st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
st->codecpar->codec_id = AV_CODEC_ID_MICRODVD;
return 0;
+fail:
+ ff_subtitles_queue_clean(&microdvd->q);
+ return ret;
}
static int microdvd_read_packet(AVFormatContext *s, AVPacket *pkt)