Commit 330a757d authored by Andreas Rheinhardt's avatar Andreas Rheinhardt

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: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
(cherry picked from commit b12014a5b861959fd41a32ba3ff4cb139c56efcd)
parent ea27fe48
...@@ -81,7 +81,7 @@ static int microdvd_read_header(AVFormatContext *s) ...@@ -81,7 +81,7 @@ static int microdvd_read_header(AVFormatContext *s)
AVRational pts_info = (AVRational){ 2997, 125 }; /* default: 23.976 fps */ AVRational pts_info = (AVRational){ 2997, 125 }; /* default: 23.976 fps */
MicroDVDContext *microdvd = s->priv_data; MicroDVDContext *microdvd = s->priv_data;
AVStream *st = avformat_new_stream(s, NULL); AVStream *st = avformat_new_stream(s, NULL);
int i = 0; int i = 0, ret;
char line_buf[MAX_LINESIZE]; char line_buf[MAX_LINESIZE];
int has_real_fps = 0; int has_real_fps = 0;
...@@ -117,10 +117,10 @@ static int microdvd_read_header(AVFormatContext *s) ...@@ -117,10 +117,10 @@ static int microdvd_read_header(AVFormatContext *s)
continue; continue;
} }
if (!st->codecpar->extradata && sscanf(line, "{DEFAULT}{}%c", &c) == 1) { 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); ret = ff_alloc_extradata(st->codecpar, size);
if (ret < 0) if (ret < 0)
return ret; goto fail;
memcpy(st->codecpar->extradata, line + 11, size); memcpy(st->codecpar->extradata, line + 11, size);
continue; continue;
} }
...@@ -138,8 +138,10 @@ static int microdvd_read_header(AVFormatContext *s) ...@@ -138,8 +138,10 @@ static int microdvd_read_header(AVFormatContext *s)
if (!*p) if (!*p)
continue; continue;
sub = ff_subtitles_queue_insert(&microdvd->q, p, strlen(p), 0); sub = ff_subtitles_queue_insert(&microdvd->q, p, strlen(p), 0);
if (!sub) if (!sub) {
return AVERROR(ENOMEM); ret = AVERROR(ENOMEM);
goto fail;
}
sub->pos = pos; sub->pos = pos;
sub->pts = get_pts(line); sub->pts = get_pts(line);
sub->duration = get_duration(line); sub->duration = get_duration(line);
...@@ -156,6 +158,9 @@ static int microdvd_read_header(AVFormatContext *s) ...@@ -156,6 +158,9 @@ static int microdvd_read_header(AVFormatContext *s)
st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE; st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
st->codecpar->codec_id = AV_CODEC_ID_MICRODVD; st->codecpar->codec_id = AV_CODEC_ID_MICRODVD;
return 0; return 0;
fail:
ff_subtitles_queue_clean(&microdvd->q);
return ret;
} }
static int microdvd_read_packet(AVFormatContext *s, AVPacket *pkt) static int microdvd_read_packet(AVFormatContext *s, AVPacket *pkt)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment