On 28/04/15 20:58, Andreas Cadhalpun wrote:
> Signed-off-by: Andreas Cadhalpun <[email protected]>
> ---
>  libavformat/nutdec.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
> 
> diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
> index 2049f70..191b285 100644
> --- a/libavformat/nutdec.c
> +++ b/libavformat/nutdec.c
> @@ -745,12 +745,14 @@ fail:
>      return ret;
>  }
>  
> +static int nut_read_close(AVFormatContext *s);
> +
>  static int nut_read_header(AVFormatContext *s)
>  {
>      NUTContext *nut = s->priv_data;
>      AVIOContext *bc = s->pb;
>      int64_t pos;
> -    int initialized_stream_count;
> +    int initialized_stream_count, ret = 0;
>  
>      nut->avf = s;
>  
> @@ -760,7 +762,8 @@ static int nut_read_header(AVFormatContext *s)
>          pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1;
>          if (pos < 0 + 1) {
>              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);
>  
> @@ -770,7 +773,8 @@ static int nut_read_header(AVFormatContext *s)
>          pos = find_startcode(bc, STREAM_STARTCODE, pos) + 1;
>          if (pos < 0 + 1) {
>              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)
>              initialized_stream_count++;
> @@ -784,7 +788,8 @@ static int nut_read_header(AVFormatContext *s)
>  
>          if (startcode == 0) {
>              av_log(s, AV_LOG_ERROR, "EOF before video frames\n");
> -            return AVERROR_INVALIDDATA;
> +            ret = AVERROR_INVALIDDATA;
> +            goto end;
>          } else if (startcode == SYNCPOINT_STARTCODE) {
>              nut->next_startcode = startcode;
>              break;
> @@ -806,7 +811,10 @@ static int nut_read_header(AVFormatContext *s)
>  
>      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)
> 

Probably something like the following is simpler though.

diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index ed28107..8a58845 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -707,7 +707,7 @@ static int nut_read_header(AVFormatContext *s)
         pos = find_startcode(bc, MAIN_STARTCODE, pos) + 1;
         if (pos < 0 + 1) {
             av_log(s, AV_LOG_ERROR, "No main startcode found.\n");
-            return AVERROR_INVALIDDATA;
+            goto fail;
         }
     } while (decode_main_header(nut) < 0);

@@ -717,7 +717,7 @@ static int nut_read_header(AVFormatContext *s)
         pos = find_startcode(bc, STREAM_STARTCODE, pos) + 1;
         if (pos < 0 + 1) {
             av_log(s, AV_LOG_ERROR, "Not all stream headers found.\n");
-            return AVERROR_INVALIDDATA;
+            goto fail;
         }
         if (decode_stream_header(nut) >= 0)
             initialized_stream_count++;
@@ -731,7 +731,7 @@ static int nut_read_header(AVFormatContext *s)

         if (startcode == 0) {
             av_log(s, AV_LOG_ERROR, "EOF before video frames\n");
-            return AVERROR_INVALIDDATA;
+            goto fail;
         } else if (startcode == SYNCPOINT_STARTCODE) {
             nut->next_startcode = startcode;
             break;
@@ -754,6 +754,11 @@ static int nut_read_header(AVFormatContext *s)
     ff_metadata_conv_ctx(s, NULL, ff_nut_metadata_conv);

     return 0;
+
+fail:
+    nut_read_close(s);
+
+    return AVERROR_INVALIDDATA;
 }

 static int decode_frame_header(NUTContext *nut, int64_t *pts, int
*stream_id,





_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to