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: 5767 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id DB61423E03 for ; Thu, 15 Dec 2011 13:33:59 +0000 (UTC) Received: from mail-ey0-f180.google.com (mail-ey0-f180.google.com [209.85.215.180]) by fiordland.canonical.com (Postfix) with ESMTP id C26BDA181ED for ; Thu, 15 Dec 2011 13:33:59 +0000 (UTC) Received: by eaak10 with SMTP id k10so2141243eaa.11 for ; Thu, 15 Dec 2011 05:33:59 -0800 (PST) Received: by 10.204.156.208 with SMTP id y16mr986827bkw.72.1323956039498; Thu, 15 Dec 2011 05:33:59 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.205.129.2 with SMTP id hg2cs41394bkc; Thu, 15 Dec 2011 05:33:59 -0800 (PST) Received: by 10.227.199.14 with SMTP id eq14mr2705182wbb.14.1323956037870; Thu, 15 Dec 2011 05:33:57 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [81.2.115.146]) by mx.google.com with ESMTPS id j10si3593637wij.16.2011.12.15.05.33.57 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 15 Dec 2011 05:33:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) client-ip=81.2.115.146; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 81.2.115.146 as permitted sender) smtp.mail=pm215@archaic.org.uk 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 Cc: patches@linaro.org, qemu-trivial@nongnu.org, Kevin Wolf , Stefan Hajnoczi Subject: [PATCH] HACKING: clarify allocation/free recommendations 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 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