From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=42158 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OFWAa-0005Ni-U1 for qemu-devel@nongnu.org; Fri, 21 May 2010 13:38:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OFWAY-0007De-TF for qemu-devel@nongnu.org; Fri, 21 May 2010 13:38:00 -0400 Received: from are.twiddle.net ([75.149.56.221]:33801) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OFWAY-0007DV-GH for qemu-devel@nongnu.org; Fri, 21 May 2010 13:37:58 -0400 From: Richard Henderson Date: Fri, 21 May 2010 10:37:51 -0700 Message-Id: <1274463472-17353-2-git-send-email-rth@twiddle.net> In-Reply-To: References: Subject: [Qemu-devel] [PATCH 1/2] Use calloc in qemu_mallocz. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: corentin.chary@gmail.com, paul@codesourcery.com, aurelien@aurel32.net, stefanha@linux.vnet.ibm.com Avoids the memset if the allocator has gotten new zeroed storage from the operating system. Signed-off-by: Richard Henderson --- qemu-malloc.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/qemu-malloc.c b/qemu-malloc.c index 6cdc5de..1b33e04 100644 --- a/qemu-malloc.c +++ b/qemu-malloc.c @@ -69,10 +69,10 @@ void *qemu_realloc(void *ptr, size_t size) void *qemu_mallocz(size_t size) { - void *ptr; - ptr = qemu_malloc(size); - memset(ptr, 0, size); - return ptr; + if (!size && !allow_zero_malloc()) { + abort(); + } + return oom_check(calloc(1, size ? size : 1)); } char *qemu_strdup(const char *str) -- 1.7.0.1