Commit 36170266 authored by Andreas Cadhalpun's avatar Andreas Cadhalpun Committed by Michael Niedermayer

nutdec: fix memleaks on error in nut_read_header

Signed-off-by: 's avatarAndreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 3ff1af2b
...@@ -745,12 +745,14 @@ fail: ...@@ -745,12 +745,14 @@ fail:
return ret; return ret;
} }
static int nut_read_close(AVFormatContext *s);
static int nut_read_header(AVFormatContext *s) static int nut_read_header(AVFormatContext *s)
{ {
NUTContext *nut = s->priv_data; NUTContext *nut = s->priv_data;
AVIOContext *bc = s->pb; AVIOContext *bc = s->pb;
int64_t pos; int64_t pos;
int initialized_stream_count; int initialized_stream_count, ret = 0;
nut->avf = s; nut->avf = s;
...@@ -760,7 +762,8 @@ static int nut_read_header(AVFormatContext *s) ...@@ -760,7 +762,8 @@ static int nut_read_header(AVFormatContext *s)
pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1; pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1;
if (pos < 0 + 1) { if (pos < 0 + 1) {
av_log(s, AV_LOG_ERROR, "No main startcode found.\n"); av_log(s, AV_LOG_ERROR, "No main startcode found.\n");
return AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;
goto end;
} }
} while (decode_main_header(nut) < 0); } while (decode_main_header(nut) < 0);
...@@ -770,7 +773,8 @@ static int nut_read_header(AVFormatContext *s) ...@@ -770,7 +773,8 @@ static int nut_read_header(AVFormatContext *s)
pos = find_startcode(bc, STREAM_STARTCODE, pos) + 1; pos = find_startcode(bc, STREAM_STARTCODE, pos) + 1;
if (pos < 0 + 1) { if (pos < 0 + 1) {
av_log(s, AV_LOG_ERROR, "Not all stream headers found.\n"); av_log(s, AV_LOG_ERROR, "Not all stream headers found.\n");
return AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;
goto end;
} }
if (decode_stream_header(nut) >= 0) if (decode_stream_header(nut) >= 0)
initialized_stream_count++; initialized_stream_count++;
...@@ -784,7 +788,8 @@ static int nut_read_header(AVFormatContext *s) ...@@ -784,7 +788,8 @@ static int nut_read_header(AVFormatContext *s)
if (startcode == 0) { if (startcode == 0) {
av_log(s, AV_LOG_ERROR, "EOF before video frames\n"); av_log(s, AV_LOG_ERROR, "EOF before video frames\n");
return AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;
goto end;
} else if (startcode == SYNCPOINT_STARTCODE) { } else if (startcode == SYNCPOINT_STARTCODE) {
nut->next_startcode = startcode; nut->next_startcode = startcode;
break; break;
...@@ -806,7 +811,10 @@ static int nut_read_header(AVFormatContext *s) ...@@ -806,7 +811,10 @@ static int nut_read_header(AVFormatContext *s)
ff_metadata_conv_ctx(s, NULL, ff_nut_metadata_conv); ff_metadata_conv_ctx(s, NULL, ff_nut_metadata_conv);
return 0; end:
if (ret < 0)
nut_read_close(s);
return FFMIN(ret, 0);
} }
static int read_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int is_meta, int64_t maxpos) static int read_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int is_meta, int64_t maxpos)
......
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