[Mesa-dev] [PATCH] util: Take memset out of rzalloc_size()

Kenneth Graunke kenneth at whitecape.org
Wed May 6 10:24:25 PDT 2015


On Wednesday, May 06, 2015 03:35:27 PM Juha-Pekka Heikkila wrote:
> rzalloc_size() call ralloc_size() to allocate memory. ralloc_size()
> use calloc to get memory thus zeroing in rzalloc_size is not
> necessary.
> 
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
>  src/util/ralloc.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/src/util/ralloc.c b/src/util/ralloc.c
> index 01719c8..09f5fcd 100644
> --- a/src/util/ralloc.c
> +++ b/src/util/ralloc.c
> @@ -132,8 +132,6 @@ void *
>  rzalloc_size(const void *ctx, size_t size)
>  {
>     void *ptr = ralloc_size(ctx, size);
> -   if (likely(ptr != NULL))
> -      memset(ptr, 0, size);
>     return ptr;
>  }
>  
> 

Wow, I have no idea why I did that.  This is certainly
counter-intuitive.

rzalloc() is supposed to guarantee zeroed memory.  ralloc() is not, but
it looks like it always has for some reason.  I'm somewhat inclined to
change ralloc_size() to use malloc instead of calloc.

I wonder how many things would break :)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150506/4ca30f3b/attachment.sig>


More information about the mesa-dev mailing list