qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH] fix qemu_malloc(0)
Date: Fri, 29 May 2009 11:33:53 +0200	[thread overview]
Message-ID: <1243589633-14142-1-git-send-email-kraxel@redhat.com> (raw)

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

             reply	other threads:[~2009-05-29  9:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-29  9:33 Gerd Hoffmann [this message]
2009-05-29  9:39 ` [Qemu-devel] [PATCH] fix qemu_malloc(0) Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1243589633-14142-1-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).