[FFmpeg-devel] [PATCH] Only do 1 malloc instead of 3 and check for failure.

Michael Niedermayer michaelni at gmx.at
Sat Oct 29 15:30:50 CEST 2011


On Sat, Oct 29, 2011 at 01:40:55PM +0200, Reimar Döffinger wrote:
> Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
> ---
>  libavcodec/proresenc.c |   12 ++++++------
>  1 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/libavcodec/proresenc.c b/libavcodec/proresenc.c
> index 7940343..e95287a 100644
> --- a/libavcodec/proresenc.c
> +++ b/libavcodec/proresenc.c
> @@ -545,9 +545,11 @@ static av_cold int prores_encode_init(AVCodecContext *avctx)
>      }
>  
>      if ((avctx->height & 0xf) || (avctx->width & 0xf)) {
> -        ctx->fill_y = av_malloc(DEFAULT_SLICE_MB_WIDTH << 9);
> -        ctx->fill_u = av_malloc(DEFAULT_SLICE_MB_WIDTH << 8);
> -        ctx->fill_v = av_malloc(DEFAULT_SLICE_MB_WIDTH << 8);
> +        ctx->fill_y = av_malloc(4 * (DEFAULT_SLICE_MB_WIDTH << 8));
> +        if (!ctx->fill_y)
> +            return AVERROR(ENOMEM);
> +        ctx->fill_u = ctx->fill_y + (DEFAULT_SLICE_MB_WIDTH << 9);
> +        ctx->fill_v = ctx->fill_u + (DEFAULT_SLICE_MB_WIDTH << 8);
>      }
>  
>      if (avctx->profile == FF_PROFILE_UNKNOWN) {
> @@ -583,9 +585,7 @@ static av_cold int prores_encode_close(AVCodecContext *avctx)
>  {
>      ProresContext* ctx = avctx->priv_data;
>      av_freep(&avctx->coded_frame);
> -    av_free(ctx->fill_y);
> -    av_free(ctx->fill_u);
> -    av_free(ctx->fill_v);
> +    av_freep(&ctx->fill_y);

LGTM

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The greatest way to live with honor in this world is to be what we pretend
to be. -- Socrates
-------------- 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/20111029/5fced247/attachment.asc>


More information about the ffmpeg-devel mailing list