Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 361702660d2c37a63b7d6381d39e1e1de8405260)
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -747,12 +747,14 @@ fail: |
747 | 747 |
return ret; |
748 | 748 |
} |
749 | 749 |
|
750 |
+static int nut_read_close(AVFormatContext *s); |
|
751 |
+ |
|
750 | 752 |
static int nut_read_header(AVFormatContext *s) |
751 | 753 |
{ |
752 | 754 |
NUTContext *nut = s->priv_data; |
753 | 755 |
AVIOContext *bc = s->pb; |
754 | 756 |
int64_t pos; |
755 |
- int initialized_stream_count; |
|
757 |
+ int initialized_stream_count, ret = 0; |
|
756 | 758 |
|
757 | 759 |
nut->avf = s; |
758 | 760 |
|
... | ... |
@@ -762,7 +764,8 @@ static int nut_read_header(AVFormatContext *s) |
762 | 762 |
pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1; |
763 | 763 |
if (pos < 0 + 1) { |
764 | 764 |
av_log(s, AV_LOG_ERROR, "No main startcode found.\n"); |
765 |
- return AVERROR_INVALIDDATA; |
|
765 |
+ ret = AVERROR_INVALIDDATA; |
|
766 |
+ goto end; |
|
766 | 767 |
} |
767 | 768 |
} while (decode_main_header(nut) < 0); |
768 | 769 |
|
... | ... |
@@ -772,7 +775,8 @@ static int nut_read_header(AVFormatContext *s) |
772 | 772 |
pos = find_startcode(bc, STREAM_STARTCODE, pos) + 1; |
773 | 773 |
if (pos < 0 + 1) { |
774 | 774 |
av_log(s, AV_LOG_ERROR, "Not all stream headers found.\n"); |
775 |
- return AVERROR_INVALIDDATA; |
|
775 |
+ ret = AVERROR_INVALIDDATA; |
|
776 |
+ goto end; |
|
776 | 777 |
} |
777 | 778 |
if (decode_stream_header(nut) >= 0) |
778 | 779 |
initialized_stream_count++; |
... | ... |
@@ -786,7 +790,8 @@ static int nut_read_header(AVFormatContext *s) |
786 | 786 |
|
787 | 787 |
if (startcode == 0) { |
788 | 788 |
av_log(s, AV_LOG_ERROR, "EOF before video frames\n"); |
789 |
- return AVERROR_INVALIDDATA; |
|
789 |
+ ret = AVERROR_INVALIDDATA; |
|
790 |
+ goto end; |
|
790 | 791 |
} else if (startcode == SYNCPOINT_STARTCODE) { |
791 | 792 |
nut->next_startcode = startcode; |
792 | 793 |
break; |
... | ... |
@@ -808,7 +813,10 @@ static int nut_read_header(AVFormatContext *s) |
808 | 808 |
|
809 | 809 |
ff_metadata_conv_ctx(s, NULL, ff_nut_metadata_conv); |
810 | 810 |
|
811 |
- return 0; |
|
811 |
+end: |
|
812 |
+ if (ret < 0) |
|
813 |
+ nut_read_close(s); |
|
814 |
+ return FFMIN(ret, 0); |
|
812 | 815 |
} |
813 | 816 |
|
814 | 817 |
static int read_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int is_meta, int64_t maxpos) |