[FFmpeg-devel] [PATCH] add av_fast_malloc

Michael Niedermayer michaelni
Sun Apr 12 14:01:03 CEST 2009


On Sun, Apr 12, 2009 at 11:39:13AM +0200, Reimar D?ffinger wrote:
> Hello,
> this adds and uses where possible a function named av_fast_malloc.
> It is very similar to av_fast_realloc and allows reusing an existing
> buffer to reduce the number of actual, slow mallocs.
> However it does not try to preserve the previous buffers contents
> (particularly with large buffers this may be faster, if we need and come
> up with a clever way to use realloc only where it is faster this can be
> added later) and it also is easier to use since handling the error case
> without creating a memleak is not as painful by far.
> Simply replacing av_fast_realloc with av_fast_malloc fixes quite a few
> memleaks...

> Index: libavcodec/motionpixels.c
> ===================================================================
> --- libavcodec/motionpixels.c	(revision 18467)
> +++ libavcodec/motionpixels.c	(working copy)
> @@ -297,7 +297,9 @@
>      }
>  
>      /* le32 bitstream msb first */
> -    mp->bswapbuf = av_fast_realloc(mp->bswapbuf, &mp->bswapbuf_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
> +    av_fast_malloc((void **)&mp->bswapbuf, &mp->bswapbuf_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
> +    if (!mp->bswapbuf)
> +        AVERROR(ENOMEM);

_Every_ single use of av_fast_malloc() uses a void** cast, av_fast_realloc()
managed it without ...

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Opposition brings concord. Out of discord comes the fairest harmony.
-- Heraclitus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090412/3eb4db35/attachment.pgp>



More information about the ffmpeg-devel mailing list