[FFmpeg-devel] [PATCH 1/2] webdashenc: Add failure check for av_malloc.

wm4 nfxjfg at googlemail.com
Tue Apr 14 10:04:47 CEST 2015


On Mon, 13 Apr 2015 12:16:31 -0700
Vignesh Venkatasubramanian <vigneshv at google.com> wrote:

> Add a missing failure check for av_malloc call.
> 
> Signed-off-by: Vignesh Venkatasubramanian <vigneshv at google.com>
> ---
>  libavformat/webmdashenc.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/webmdashenc.c b/libavformat/webmdashenc.c
> index c5347a9..80266f7 100644
> --- a/libavformat/webmdashenc.c
> +++ b/libavformat/webmdashenc.c
> @@ -87,7 +87,7 @@ static double get_duration(AVFormatContext *s)
>      return max / 1000;
>  }
>  
> -static void write_header(AVFormatContext *s)
> +static int write_header(AVFormatContext *s)
>  {
>      WebMDashMuxContext *w = s->priv_data;
>      double min_buffer_time = 1.0;
> @@ -110,6 +110,7 @@ static void write_header(AVFormatContext *s)
>          struct tm gmt_buffer;
>          struct tm *gmt = gmtime_r(&local_time, &gmt_buffer);
>          char *gmt_iso = av_malloc(21);
> +        if (!gmt_iso) return AVERROR(ENOMEM);

There is absolutely no reason why it should use malloc for 21 bytes.
I'm really wondering why you're adding a failure path instead of just
turning it into a stack allocation??????

>          strftime(gmt_iso, 21, "%Y-%m-%dT%H:%M:%SZ", gmt);
>          if (w->debug_mode) {
>              av_strlcpy(gmt_iso, "", 1);
> @@ -124,6 +125,7 @@ static void write_header(AVFormatContext *s)
>                      w->utc_timing_url ? w->utc_timing_url : gmt_iso);
>          av_free(gmt_iso);
>      }
> +    return 0;
>  }
>  
>  static void write_footer(AVFormatContext *s)
> @@ -456,7 +458,7 @@ static int webm_dash_manifest_write_header(AVFormatContext *s)
>      double start = 0.0;
>      WebMDashMuxContext *w = s->priv_data;
>      parse_adaptation_sets(s);
> -    write_header(s);
> +    if (write_header(s) < 0) return -1;
>      avio_printf(s->pb, "<Period id=\"0\"");
>      avio_printf(s->pb, " start=\"PT%gS\"", start);
>      if (!w->is_live) {



More information about the ffmpeg-devel mailing list