aboutsummaryrefslogtreecommitdiff
path: root/qemu-malloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'qemu-malloc.c')
-rw-r--r--qemu-malloc.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/qemu-malloc.c b/qemu-malloc.c
index 295d1856ef..5d9e34d69d 100644
--- a/qemu-malloc.c
+++ b/qemu-malloc.c
@@ -42,22 +42,29 @@ void qemu_free(void *ptr)
free(ptr);
}
+static int allow_zero_malloc(void)
+{
+#if defined(CONFIG_ZERO_MALLOC)
+ return 1;
+#else
+ return 0;
+#endif
+}
+
void *qemu_malloc(size_t size)
{
- if (!size) {
+ if (!size && !allow_zero_malloc()) {
abort();
}
- return oom_check(malloc(size));
+ return oom_check(malloc(size ? size : 1));
}
void *qemu_realloc(void *ptr, size_t size)
{
if (size) {
return oom_check(realloc(ptr, size));
- } else {
- if (ptr) {
- return realloc(ptr, size);
- }
+ } else if (allow_zero_malloc()) {
+ return oom_check(realloc(ptr, size ? size : 1));
}
abort();
}