Juha-Pekka found this back in May 2015: <1430915727-28677-1-git-send-email-juhapekka.heikk...@gmail.com>
From the discussion, obviously it would be preferable to make ralloc_size no longer return zeroed memory, but Juha-Pekka found that it would break Mesa. For now, let's point out the flaw, and stop doing the double zeroing of rzalloc buffers. Signed-off-by: Jordan Justen <jordan.l.jus...@intel.com> Cc: Juha-Pekka Heikkila <juhapekka.heikk...@gmail.com> Cc: Kenneth Graunke <kenn...@whitecape.org> --- For a release build, I saw the code size shrink by 64 bytes. src/util/ralloc.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/util/ralloc.c b/src/util/ralloc.c index 6d4032b..24c1eee 100644 --- a/src/util/ralloc.c +++ b/src/util/ralloc.c @@ -49,6 +49,14 @@ _CRTIMP int _vscprintf(const char *format, va_list argptr); #endif #endif +/* ralloc_size has always used calloc to allocate memory. This has allowed + * code using ralloc_size to depend on always receiving a cleared buffer. + * + * FIXME: Clean up the code base to allow this to be set to false, and then + * remove it altogether. + */ +static const bool always_allocate_zeroed_memory = true; + #define CANARY 0x5A1106 struct ralloc_header @@ -110,7 +118,10 @@ ralloc_context(const void *ctx) void * ralloc_size(const void *ctx, size_t size) { - void *block = calloc(1, size + sizeof(ralloc_header)); + void *block = + always_allocate_zeroed_memory ? + calloc(1, size + sizeof(ralloc_header)) : + malloc(size + sizeof(ralloc_header)); ralloc_header *info; ralloc_header *parent; @@ -132,7 +143,7 @@ void * rzalloc_size(const void *ctx, size_t size) { void *ptr = ralloc_size(ctx, size); - if (likely(ptr != NULL)) + if (!always_allocate_zeroed_memory && likely(ptr != NULL)) memset(ptr, 0, size); return ptr; } -- 2.6.2 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev