[FFmpeg-devel] [PATCH] Add and use av_fast_padded_malloc.

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sun Jan 15 22:26:39 CET 2012


On Sun, Jan 15, 2012 at 10:10:00PM +0100, Michael Niedermayer wrote:
> On Sun, Jan 15, 2012 at 09:52:22PM +0100, Reimar Döffinger wrote:
> > The same as av_fast_malloc but uses av_mallocz and keeps extra
> > always-0 padding.
> > This does not mean the memory will be 0-initialized after each call,
> > but actually only after each growth of the buffer.
> > However this makes sure that
> > a) all data anywhere in the buffer is always initialized
> > b) the padding is always 0
> > c) the user does not have to bother with adding the padding themselves
> > Fixes another valgrind warning about use of uninitialized data,
> > this time with fate-vsynth1-jpegls.
> [...]
> > +void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
> > +{
> > +    if (!ff_fast_malloc(ptr, size, min_size + FF_INPUT_BUFFER_PADDING_SIZE, 1))
> > +        memset(ptr + min_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
> 
> possible integer overflow, except that i like this patch alot more than
> the last

Yes, it also has a bug, since ptr is not the pointer to the allocated
memory but pointer to pointer.
But if it seems reasonable I'll polish it a bit.


More information about the ffmpeg-devel mailing list