Patchwork [1/2] Use calloc in qemu_mallocz.

login
register
mail settings
Submitter Richard Henderson
Date May 21, 2010, 5:37 p.m.
Message ID <1274463472-17353-2-git-send-email-rth@twiddle.net>
Download mbox | patch
Permalink /patch/53197/
State New
Headers show

Comments

Richard Henderson - May 21, 2010, 5:37 p.m.
Avoids the memset if the allocator has gotten new zeroed
storage from the operating system.

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 qemu-malloc.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

Patch

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)