[FFmpeg-devel] [PATCH] add av_fast_malloc
Sun Apr 12 14:42:01 CEST 2009
On Sun, Apr 12, 2009 at 02:10:58PM +0200, Reimar D?ffinger wrote:
> 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
do you have a plan on how to silence diego?
> Or you could give av_fast_malloc a return value, but IMO that would be
> a more confusing API.
i always liked to make it explicit what is changed by using return ...
> 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...
make the arg void * and cast inside the function if you dislie the return
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
It is dangerous to be right in matters on which the established authorities
are wrong. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: Digital signature
More information about the ffmpeg-devel