[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] fix qemu_malloc(0)
From: |
Gerd Hoffmann |
Subject: |
[Qemu-devel] [PATCH] fix qemu_malloc(0) |
Date: |
Fri, 29 May 2009 11:33:53 +0200 |
Don't abort. Return malloc(1) instead as suggested by Anthony.
Likewise kill the abort call in qemu_realloc(), we can just call
free(ptr) for the size == 0 case to match realloc() behavior.
Signed-off-by: Gerd Hoffmann <address@hidden>
---
qemu-malloc.c | 9 +++------
1 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/qemu-malloc.c b/qemu-malloc.c
index 295d185..4193fdb 100644
--- a/qemu-malloc.c
+++ b/qemu-malloc.c
@@ -45,7 +45,7 @@ void qemu_free(void *ptr)
void *qemu_malloc(size_t size)
{
if (!size) {
- abort();
+ size = 1;
}
return oom_check(malloc(size));
}
@@ -54,12 +54,9 @@ void *qemu_realloc(void *ptr, size_t size)
{
if (size) {
return oom_check(realloc(ptr, size));
- } else {
- if (ptr) {
- return realloc(ptr, size);
- }
}
- abort();
+ free(ptr);
+ return NULL;
}
void *qemu_mallocz(size_t size)
--
1.6.2.2
- [Qemu-devel] [PATCH] fix qemu_malloc(0),
Gerd Hoffmann <=