[FFmpeg-devel] [PATCH 2/2] avutil/mem: Also poison new av_realloc-allocated blocks

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Fri Apr 30 00:07:36 EEST 2021


Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> ---
>  libavutil/mem.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/libavutil/mem.c b/libavutil/mem.c
> index cfb6d8ab8f..fa227f5e12 100644
> --- a/libavutil/mem.c
> +++ b/libavutil/mem.c
> @@ -133,14 +133,20 @@ void *av_malloc(size_t size)
>  
>  void *av_realloc(void *ptr, size_t size)
>  {
> +    void *ret;
>      if (size > max_alloc_size)
>          return NULL;
>  
>  #if HAVE_ALIGNED_MALLOC
> -    return _aligned_realloc(ptr, size + !size, ALIGN);
> +    ret = _aligned_realloc(ptr, size + !size, ALIGN);
>  #else
> -    return realloc(ptr, size + !size);
> +    ret = realloc(ptr, size + !size);
>  #endif
> +#if CONFIG_MEMORY_POISONING
> +    if (ret && !ptr)
> +        memset(ret, FF_MEMORY_POISON, size);
> +#endif
> +    return ret;
>  }
>  
>  void *av_realloc_f(void *ptr, size_t nelem, size_t elsize)
> 
Will apply this tomorrow unless there are objections.

- Andreas


More information about the ffmpeg-devel mailing list