[FFmpeg-devel] [PATCH v1 4/4] avformat/hlsenc: use av_asprintf()

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Wed Apr 8 17:39:09 EEST 2020


Steven Liu:
> 
> 
>> 2020年3月26日 下午9:57,lance.lmwang at gmail.com 写道:
>>
>> From: Limin Wang <lance.lmwang at gmail.com>
>>
>> Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
>> ---
>> libavformat/hlsenc.c | 4 +---
>> 1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
>> index d7b9c0e20a..694dab42dd 100644
>> --- a/libavformat/hlsenc.c
>> +++ b/libavformat/hlsenc.c
>> @@ -2950,13 +2950,11 @@ static int hls_init(AVFormatContext *s)
>>                 if (ret < 0)
>>                     goto fail;
>>             } else {
>> -                vs->vtt_m3u8_name = av_malloc(vtt_basename_size);
>> +                vs->vtt_m3u8_name = av_asprintf("%s_vtt.m3u8", vs->vtt_basename);
> As mkver suggestion, perhaps use bprint is better, is it?

The situation here is completely different: The lifetime of the strings
for which I used an AVBPrint was just a part of a function call, ergo it
can be replaced with a buffer on the stack (if the string is small
enough). But the lifetime of vs->vtt_m3u8_name extends beyond
hls_init(), ergo it can't be put on the stack (as is implicitly done
when using an AVBPrint). It needs to be allocated on the heap.

- Andreas


More information about the ffmpeg-devel mailing list