From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M9yTU-0004FO-JA for qemu-devel@nongnu.org; Fri, 29 May 2009 05:34:04 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M9yTP-0004D6-I9 for qemu-devel@nongnu.org; Fri, 29 May 2009 05:34:03 -0400 Received: from [199.232.76.173] (port=55147 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M9yTP-0004D1-6T for qemu-devel@nongnu.org; Fri, 29 May 2009 05:33:59 -0400 Received: from mx2.redhat.com ([66.187.237.31]:34298) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M9yTO-0003dF-FN for qemu-devel@nongnu.org; Fri, 29 May 2009 05:33:58 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n4T9XvMS016390 for ; Fri, 29 May 2009 05:33:57 -0400 From: Gerd Hoffmann Date: Fri, 29 May 2009 11:33:53 +0200 Message-Id: <1243589633-14142-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH] fix qemu_malloc(0) List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- 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