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

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sun Jan 15 21:42:04 CET 2012


On Sun, Jan 15, 2012 at 09:10:49PM +0100, Michael Niedermayer wrote:
> On Sun, Jan 15, 2012 at 02:29:59PM +0100, Reimar Döffinger wrote:
> > The same as av_fast_malloc but uses av_mallocz.
> > 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) any padding is always 0
> > Fixes another valgrind warning about use of uninitialized data,
> > this time with fate-vsynth1-jpegls.
> > 
> > Signed-off-by: Reimar Döffinger <Reimar.Doeffinger at gmx.de>
> > ---
> >  libavcodec/asv1.c     |    3 +--
> >  libavcodec/avcodec.h  |    9 +++++++++
> >  libavcodec/mjpegdec.c |   10 +++-------
> >  libavcodec/utils.c    |   14 ++++++++++++--
> >  4 files changed, 25 insertions(+), 11 deletions(-)
> > 
> > diff --git a/libavcodec/asv1.c b/libavcodec/asv1.c
> > index a2519cb..75aa0e1 100644
> > --- a/libavcodec/asv1.c
> > +++ b/libavcodec/asv1.c
> > @@ -408,10 +408,9 @@ static int decode_frame(AVCodecContext *avctx,
> >      p->pict_type= AV_PICTURE_TYPE_I;
> >      p->key_frame= 1;
> >  
> > -    av_fast_malloc(&a->bitstream_buffer, &a->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
> > +    av_fast_mallocz(&a->bitstream_buffer, &a->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
> >      if (!a->bitstream_buffer)
> >          return AVERROR(ENOMEM);
> > -    memset(a->bitstream_buffer + buf_size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
> 
> if a buffer becomes smaller the padding after the new buffer wont be 0
> but instead the 0 padding would be farther away.
> Iam not sure if this might have some side effect for some codec ...

Hm. It's a bit ugly, but I'll send a different proposal.
Not sure what's best, just throwing out ideas to see what sticks :-).
In principle none of these are a big deal so we can always say we leave
it, but valgrind running through is worth something, as well as
helper functions that make it easy to do the right thing.


More information about the ffmpeg-devel mailing list