From patchwork Thu Dec 15 13:33:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 131612 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C52DC1007D7 for ; Fri, 16 Dec 2011 00:34:22 +1100 (EST) Received: from localhost ([::1]:55955 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RbBRy-0006vQ-QH for incoming@patchwork.ozlabs.org; Thu, 15 Dec 2011 08:34:18 -0500 Received: from eggs.gnu.org ([140.186.70.92]:38885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RbBRp-0006tJ-WA for qemu-devel@nongnu.org; Thu, 15 Dec 2011 08:34:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RbBRk-0005I5-7c for qemu-devel@nongnu.org; Thu, 15 Dec 2011 08:34:09 -0500 Received: from mnementh.archaic.org.uk ([81.2.115.146]:51282) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RbBRj-0005HT-Vg; Thu, 15 Dec 2011 08:34:04 -0500 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1RbBRa-0005ah-1z; Thu, 15 Dec 2011 13:33:54 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 15 Dec 2011 13:33:54 +0000 Message-Id: <1323956034-21468-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 81.2.115.146 Cc: qemu-trivial@nongnu.org, Kevin Wolf , Stefan Hajnoczi , patches@linaro.org Subject: [Qemu-devel] [PATCH] HACKING: clarify allocation/free recommendations X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Clarify the allocation/free recommendations; this is mostly just tidying up following the global-search-and-replace done with the conversion to the GLib g_malloc and friends. Signed-off-by: Peter Maydell Reviewed-by: Stefan Hajnoczi --- HACKING | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/HACKING b/HACKING index 733eab2..471cf1d 100644 --- a/HACKING +++ b/HACKING @@ -77,11 +77,13 @@ avoided. Use of the malloc/free/realloc/calloc/valloc/memalign/posix_memalign APIs is not allowed in the QEMU codebase. Instead of these routines, -use the replacement g_malloc/g_malloc0/g_realloc/g_free or -qemu_vmalloc/qemu_memalign/qemu_vfree APIs. +use the GLib memory allocation routines g_malloc/g_malloc0/g_new/ +g_new0/g_realloc/g_free or QEMU's qemu_vmalloc/qemu_memalign/qemu_vfree +APIs. -Please note that NULL check for the g_malloc result is redundant and -that g_malloc() call with zero size is not allowed. +Please note that g_malloc will exit on allocation failure, so there +is no need to test for failure (as you would have to with malloc). +Calling g_malloc with a zero size is valid and will return NULL. Memory allocated by qemu_vmalloc or qemu_memalign must be freed with qemu_vfree, since breaking this will cause problems on Win32 and user