[FFmpeg-devel] [PATCH] oggparsevorbis: use av_realloc consistently

Paweł Hajdan phajdan at google.com
Wed Jan 30 17:30:33 CET 2013


Could you please take another look at the patch below now that
http://ffmpeg.org/pipermail/ffmpeg-devel/2013-January/138150.html has been
committed? (thanks!)

It seems at least in what's covered by Chrome test suite and "make fate",
these are the only two cases of mixing memalign and realloc.

Paweł


On Thu, Jan 10, 2013 at 7:24 PM, Paweł Hajdan, Jr <phajdan at google.com>wrote:

> From: "Paweł Hajdan, Jr" <phajdan at google.com>
>
> Memory passed to av_realloc cannot be allocated using memalign.
>
> From realloc(3):
>
> The realloc() function changes the size of the memory block pointed to
> by ptr to size bytes. (...) Unless ptr is NULL, it must have been returned
> by an earlier call to malloc(), calloc() or realloc().
>
> The issue has been found by debugallocation, a part of google-perftools:
> http://code.google.com/p/gperftools/ .
>
> Signed-off-by: Paweł Hajdan, Jr <phajdan at google.com>
> ---
>  libavformat/oggparsevorbis.c |    6 ++++--
>  1 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/libavformat/oggparsevorbis.c b/libavformat/oggparsevorbis.c
> index 16bcaef..452d856 100644
> --- a/libavformat/oggparsevorbis.c
> +++ b/libavformat/oggparsevorbis.c
> @@ -173,11 +173,13 @@ static unsigned int
>  fixup_vorbis_headers(AVFormatContext * as, struct oggvorbis_private *priv,
>                       uint8_t **buf)
>  {
> -    int i,offset, len;
> +    int i,offset, len, buf_len;
>      unsigned char *ptr;
>
>      len = priv->len[0] + priv->len[1] + priv->len[2];
> -    ptr = *buf = av_mallocz(len + len/255 + 64);
> +    buf_len = len + len/255 + 64;
> +    ptr = *buf = av_realloc(NULL, buf_len);
> +    memset(*buf, '\0', buf_len);
>
>      ptr[0] = 2;
>      offset = 1;
> --
> 1.7.7.3
>
>


More information about the ffmpeg-devel mailing list