From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M69Uj-0008Rg-J4 for qemu-devel@nongnu.org; Mon, 18 May 2009 16:31:33 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M69Ue-0008RU-LL for qemu-devel@nongnu.org; Mon, 18 May 2009 16:31:32 -0400 Received: from [199.232.76.173] (port=35224 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M69Ue-0008RR-HQ for qemu-devel@nongnu.org; Mon, 18 May 2009 16:31:28 -0400 Received: from mx2.redhat.com ([66.187.237.31]:56329) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M69Ue-0004mk-2e for qemu-devel@nongnu.org; Mon, 18 May 2009 16:31:28 -0400 From: Eduardo Habkost Date: Mon, 18 May 2009 17:31:16 -0300 Message-Id: <1242678676-19439-1-git-send-email-ehabkost@redhat.com> Subject: [Qemu-devel] [PATCH] fix qemu_malloc() error check for size==0 List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel@nongnu.org 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 --- 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 -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