[FFmpeg-devel] [libav-devel] [PATCH 3/3] nutdec: fix memleaks on error in nut_read_header

Andreas Cadhalpun andreas.cadhalpun at googlemail.com
Wed Apr 29 22:54:55 CEST 2015


On 29.04.2015 21:28, Luca Barbato wrote:
> 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,

Yes, that's simpler, but my variant is more easy to change in the future,
if e.g. some path should return a different error code.
I have no idea how likely that is, though.

Best regards,
Andreas



More information about the ffmpeg-devel mailing list