qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] fix qemu_malloc(0)
@ 2009-05-29  9:33 Gerd Hoffmann
  2009-05-29  9:39 ` Anthony Liguori
  0 siblings, 1 reply; 2+ messages in thread
From: Gerd Hoffmann @ 2009-05-29  9:33 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

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 <kraxel@redhat.com>
---
 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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-05-29  9:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-29  9:33 [Qemu-devel] [PATCH] fix qemu_malloc(0) Gerd Hoffmann
2009-05-29  9:39 ` Anthony Liguori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).