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

Michael Niedermayer michaelni at gmx.at
Sun Jan 15 21:10:49 CET 2012


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 ...

[....]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Into a blind darkness they enter who follow after the Ignorance,
they as if into a greater darkness enter who devote themselves
to the Knowledge alone. -- Isha Upanishad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120115/7e0ed8d0/attachment.asc>


More information about the ffmpeg-devel mailing list