From patchwork Mon Dec 28 15:49:00 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 41854 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 60B6FB6EEF for ; Tue, 29 Dec 2009 02:51:53 +1100 (EST) Received: from localhost ([127.0.0.1]:47116 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NPHss-0003XG-9q for incoming@patchwork.ozlabs.org; Mon, 28 Dec 2009 10:51:50 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NPHsO-0003VS-CE for qemu-devel@nongnu.org; Mon, 28 Dec 2009 10:51:20 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NPHsM-0003VB-OU for qemu-devel@nongnu.org; Mon, 28 Dec 2009 10:51:19 -0500 Received: from [199.232.76.173] (port=44104 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NPHsM-0003V8-J9 for qemu-devel@nongnu.org; Mon, 28 Dec 2009 10:51:18 -0500 Received: from hall.aurel32.net ([88.191.82.174]:54418) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NPHsM-00055x-8d for qemu-devel@nongnu.org; Mon, 28 Dec 2009 10:51:18 -0500 Received: from [80.214.254.68] (helo=volta.aurel32.net) by hall.aurel32.net with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1NPHsI-0001Qp-Ow for qemu-devel@nongnu.org; Mon, 28 Dec 2009 16:51:16 +0100 Received: from aurel32 by volta.aurel32.net with local (Exim 4.69) (envelope-from ) id 1NPHq8-0003JH-Jq for qemu-devel@nongnu.org; Mon, 28 Dec 2009 16:49:00 +0100 Date: Mon, 28 Dec 2009 16:49:00 +0100 From: Aurelien Jarno To: qemu-devel@nongnu.org Message-ID: <20091228154900.GE4908@volta.aurel32.net> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [Qemu-devel] [PATCH] Allow usage of qemu_realloc(ptr, 0) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org realloc(ptr, 0) is always allowed by the standard. The return value is either NULL or a pointer that can be freed with free(). Allow usage of qemu_realloc(ptr, 0), and return NULL in that case, as free(NULL) should always be a nop. This fixes -kernel with stripped kernels. Signed-off-by: Aurelien Jarno --- qemu-malloc.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/qemu-malloc.c b/qemu-malloc.c index 5d9e34d..cf6a1f1 100644 --- a/qemu-malloc.c +++ b/qemu-malloc.c @@ -63,10 +63,10 @@ void *qemu_realloc(void *ptr, size_t size) { if (size) { return oom_check(realloc(ptr, size)); - } else if (allow_zero_malloc()) { - return oom_check(realloc(ptr, size ? size : 1)); + } else if (ptr) { + qemu_free(ptr); } - abort(); + return NULL; } void *qemu_mallocz(size_t size)