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

Vignesh Venkatasubramanian vigneshv at google.com
Tue Apr 14 19:30:15 CEST 2015


On Tue, Apr 14, 2015 at 1:04 AM, wm4 <nfxjfg at googlemail.com> wrote:
> 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??????
>

sorry! changed to stack allocation now.

>>          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) {
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel



-- 
Vignesh


More information about the ffmpeg-devel mailing list