diff mbox series

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

Message ID HE1PR0301MB21547450E5A5AF6319E6C32D8F429@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit 8b83a4a885e3b92bd09354d6cb182fca47f80973
Headers show
Series [FFmpeg-devel,1/2] avcodec/vc2enc: Actually zero padding | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt April 26, 2021, 5:19 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavutil/mem.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Andreas Rheinhardt April 29, 2021, 9:07 p.m. UTC | #1
Andreas Rheinhardt:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@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
diff mbox series

Patch

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)