[FFmpeg-devel] Patch: explicitly initialize AVFormatContext *ic = NULL

Benoit Fouet benoit.fouet
Wed Jul 15 12:00:26 CEST 2009


On 2009-07-11 04:46, Michael Niedermayer wrote:
> On Fri, Jul 10, 2009 at 11:55:57AM -0700, Art Clarke wrote:
>> On Thu, Jul 9, 2009 at 7:41 PM, avcoder <ffmpeg at gmail.com> wrote:
>>
>>>>> But IMHO, Initialize AVForamatContext *ic = NULL is a safe coding
>>>>> style, and this modification unifies coding style with other
>>>>> av_open_input_file() usages in ffmpeg internal source code
>>>> The problem is that =NULL is in the applications (ffmpeg/ffplay/...)
>>>> and the ABI/API does not seem to require it, adding that requirement
>>>> makes libav incompatible with old applications ...
>>> I see, so revert is a better choice
>>
>>
>> Or, actually special case the original problem; a caller has pre-allocated a
>> context and passed it in (wherein av_open_input_file assumes memory
>> ownership).  Patch attached.
>>
>> - Art
>>
>> Index: libavformat/utils.c
>> ===================================================================
>> --- libavformat/utils.c	(revision 19394)
>> +++ libavformat/utils.c	(working copy)
>> @@ -499,7 +499,10 @@
>>      av_freep(&pd->buf);
>>      if (pb)
>>          url_fclose(pb);
>> -    av_freep(ic_ptr);
>> +    if (ap && ap->prealloced_context)
>> +        av_freep(ic_ptr);
>> +    else
>> +        *ic_ptr = NULL;
> 
> if()
>     av_free()
> =NULL
> 

applied this way.

Ben



More information about the ffmpeg-devel mailing list