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

Michael Niedermayer michaelni at gmx.at
Fri Jul 12 22:00:16 CEST 2013


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?

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The educated differ from the uneducated as much as the living from the
dead. -- Aristotle 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130712/243d7219/attachment.asc>


More information about the ffmpeg-devel mailing list