From: Marek Olšák <marek.ol...@amd.com> only do it in rzalloc_size as it was supposed to be --- src/util/ralloc.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-)
diff --git a/src/util/ralloc.c b/src/util/ralloc.c index 23c89e5..bf21ac3 100644 --- a/src/util/ralloc.c +++ b/src/util/ralloc.c @@ -106,62 +106,58 @@ add_child(ralloc_header *parent, ralloc_header *info) void * ralloc_context(const void *ctx) { return ralloc_size(ctx, 0); } void * ralloc_size(const void *ctx, size_t size) { - /* ralloc_size was originally implemented using calloc, which meant some - * code accidentally relied on its zero filling behavior. - * - * TODO: Make ralloc_size not zero fill memory, and cleanup any code that - * should instead be using rzalloc. - */ - return rzalloc_size(ctx, size); -} - -void * -rzalloc_size(const void *ctx, size_t size) -{ void *block = malloc(size + sizeof(ralloc_header)); ralloc_header *info; ralloc_header *parent; if (unlikely(block == NULL)) return NULL; info = (ralloc_header *) block; /* measurements have shown that calloc is slower, so clear things * manually */ info->child = NULL; info->prev = NULL; info->destructor = NULL; /* add_child() clears other members */ - /* memset the allocation except for ralloc_header */ - memset(&info[1], 0, size); - parent = ctx != NULL ? get_header(ctx) : NULL; add_child(parent, info); #ifdef DEBUG info->canary = CANARY; #endif return PTR_FROM_HEADER(info); } +void * +rzalloc_size(const void *ctx, size_t size) +{ + void *ptr = ralloc_size(ctx, size); + + if (likely(ptr)) + memset(ptr, 0, size); + + return ptr; +} + /* helper function - assumes ptr != NULL */ static void * resize(void *ptr, size_t size) { ralloc_header *child, *old, *info; old = get_header(ptr); info = realloc(old, size + sizeof(ralloc_header)); if (info == NULL) -- 2.7.4 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev