Use calloc in qemu_mallocz.
authorRichard Henderson <rth@twiddle.net>
Fri, 21 May 2010 17:37:51 +0000 (10:37 -0700)
committerAurelien Jarno <aurelien@aurel32.net>
Fri, 28 May 2010 21:27:19 +0000 (23:27 +0200)
Avoids the memset if the allocator has gotten new zeroed
storage from the operating system.

Signed-off-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
qemu-malloc.c

index 6cdc5de..1b33e04 100644 (file)
@@ -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)