qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: Anthony Liguori <anthony@codemonkey.ws>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] fix qemu_malloc() error check for size==0
Date: Mon, 18 May 2009 17:31:16 -0300	[thread overview]
Message-ID: <1242678676-19439-1-git-send-email-ehabkost@redhat.com> (raw)

This patch is similar to a previous qemu_realloc() fix
(commit 322691a5c9f1c8531554148d47c078b5be590805), but for qemu_malloc().

malloc(0) may correctly return NULL if size==0. We don't want to abort qemu on
this case.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 qemu-malloc.c |   11 ++++-------
 1 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/qemu-malloc.c b/qemu-malloc.c
index 6761857..2c60969 100644
--- a/qemu-malloc.c
+++ b/qemu-malloc.c
@@ -24,9 +24,9 @@
 #include "qemu-common.h"
 #include <stdlib.h>
 
-static void *oom_check(void *ptr)
+static void *oom_check(size_t size, void *ptr)
 {
-    if (ptr == NULL)
+    if (size != 0 && ptr == NULL)
         abort();
     return ptr;
 }
@@ -43,15 +43,12 @@ void qemu_free(void *ptr)
 
 void *qemu_malloc(size_t size)
 {
-    return oom_check(malloc(size));
+    return oom_check(size, malloc(size));
 }
 
 void *qemu_realloc(void *ptr, size_t size)
 {
-    if (size)
-        return oom_check(realloc(ptr, size));
-    else
-        return realloc(ptr, size);
+    return oom_check(size, realloc(ptr, size));
 }
 
 void *qemu_mallocz(size_t size)
-- 
1.6.3.rc4.29.g8146

             reply	other threads:[~2009-05-18 20:31 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-18 20:31 Eduardo Habkost [this message]
2009-05-18 21:56 ` [Qemu-devel] [PATCH] fix qemu_malloc() error check for size==0 malc
2009-05-18 22:17   ` Eduardo Habkost
2009-05-19  0:17     ` malc
2009-05-19  6:44       ` Markus Armbruster
2009-05-19 13:00         ` malc
2009-05-19 13:37           ` Markus Armbruster
2009-05-19 14:06             ` malc
2009-05-19 14:28               ` Eduardo Habkost
2009-05-19 14:48                 ` malc
2009-05-19 14:56                   ` Eduardo Habkost
2009-05-19 15:23                     ` malc
2009-05-19 15:43                       ` Eduardo Habkost
2009-05-19 20:32                         ` Jamie Lokier
2009-05-19 22:12                           ` Eduardo Habkost
2009-05-19 22:49                             ` Jamie Lokier
2009-05-20  3:28                               ` Eduardo Habkost
2009-05-19 20:31                     ` Jamie Lokier
2009-05-19 16:09               ` Markus Armbruster
2009-05-19 14:02           ` Eduardo Habkost
2009-05-19 14:37             ` malc
2009-05-19 14:44               ` Eduardo Habkost
2009-05-19 14:55                 ` malc
2009-05-19 16:44                   ` [PATCH] Make qemu_alloc()/qemu_realloc() return NULL for size==0 (was Re: [Qemu-devel] [PATCH] fix qemu_malloc() error check for size==0) Eduardo Habkost
2009-05-19 18:40                     ` malc
2009-05-19 19:38                       ` Eduardo Habkost
2009-05-19 20:34                       ` Jamie Lokier
2009-05-20  8:00                       ` Kevin Wolf
2009-05-20  9:30                       ` [Qemu-devel] Re: [PATCH] Make qemu_alloc()/qemu_realloc() return NULL for size==0 Markus Armbruster
2009-05-20 18:20                         ` malc
2009-05-19 20:37                   ` [Qemu-devel] [PATCH] fix qemu_malloc() error check " Jamie Lokier
2009-05-19 13:52       ` Eduardo Habkost
2009-05-19 14:39         ` malc

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=1242678676-19439-1-git-send-email-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=anthony@codemonkey.ws \
    --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).