[FFmpeg-devel] [PATCH] add av_fast_malloc
Reimar Döffinger
Reimar.Doeffinger
Sun Apr 12 14:10:58 CEST 2009
On Sun, Apr 12, 2009 at 02:01:03PM +0200, Michael Niedermayer wrote:
> 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 ...
Yes, what can I do... You could of course just ignore the compiler
warnings.
Or you could give av_fast_malloc a return value, but IMO that would be
a more confusing API.
In several cases the buffer could be made void *, sometimes avoiding a
few more casts in the process.
There are many solutions, I just considered this the best...
More information about the ffmpeg-devel
mailing list