[FFmpeg-devel] [PATCH 1/2] lavfi: check for allocation failure in ff_insert_pad()

Paul B Mahol onemda at gmail.com
Fri Jul 12 22:03:13 CEST 2013


On 7/12/13, Michael Niedermayer <michaelni at gmx.at> wrote:
> On Wed, Jul 10, 2013 at 10:00:47PM +0000, Paul B Mahol wrote:
>> Signed-off-by: Paul B Mahol <onemda at gmail.com>
>> ---
>>  libavfilter/avfilter.c | 9 ++++++---
>>  libavfilter/internal.h | 3 ++-
>>  2 files changed, 8 insertions(+), 4 deletions(-)
>>
>> diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
>> index c3228cd..b05f4e8 100644
>> --- a/libavfilter/avfilter.c
>> +++ b/libavfilter/avfilter.c
>> @@ -93,7 +93,7 @@ void ff_command_queue_pop(AVFilterContext *filter)
>>      av_free(c);
>>  }
>>
>> -void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
>> +int ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
>>                     AVFilterPad **pads, AVFilterLink ***links,
>>                     AVFilterPad *newpad)
>>  {
>> @@ -101,8 +101,10 @@ void ff_insert_pad(unsigned idx, unsigned *count,
>> size_t padidx_off,
>>
>>      idx = FFMIN(idx, *count);
>>
>> -    *pads  = av_realloc(*pads,  sizeof(AVFilterPad)   * (*count + 1));
>> -    *links = av_realloc(*links, sizeof(AVFilterLink*) * (*count + 1));
>> +    *pads  = av_realloc_f(*pads, *count + 1, sizeof(AVFilterPad));
>> +    *links = av_realloc_f(*links, *count + 1, sizeof(AVFilterLink*));
>> +    if (!*pads || !*links)
>> +        return AVERROR(ENOMEM);
>
> this causes the memory to be deallocated on failure, is that intended?

Considering that allocation failure for current code is ignored why would this
one make a difference?

>
> [...]
>
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> The educated differ from the uneducated as much as the living from the
> dead. -- Aristotle
>


More information about the ffmpeg-devel mailing list