From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=55404 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OouZA-0000gg-Ss for qemu-devel@nongnu.org; Fri, 27 Aug 2010 04:45:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OouZ9-000827-O5 for qemu-devel@nongnu.org; Fri, 27 Aug 2010 04:45:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1026) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OouZ9-00081x-GX for qemu-devel@nongnu.org; Fri, 27 Aug 2010 04:45:39 -0400 Message-ID: <4C777B39.5050708@redhat.com> Date: Fri, 27 Aug 2010 10:45:45 +0200 From: Kevin Wolf MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 3/5] HACKING: add memory management rules References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: qemu-devel Am 26.08.2010 20:38, schrieb Blue Swirl: > Add memory management rules, somewhat like libvirt HACKING. > > Signed-off-by: Blue Swirl > --- > HACKING | 11 +++++++++++ > 1 files changed, 11 insertions(+), 0 deletions(-) > > diff --git a/HACKING b/HACKING > index 19fc874..554009e 100644 > --- a/HACKING > +++ b/HACKING > @@ -72,3 +72,14 @@ Typedefs are used to eliminate the redundant > 'struct' keyword. > 2.4. Reserved namespaces in C > Underscore capital, double underscore, and underscore 't' suffixes should be > avoided. > + > +3. Low level memory management > + > +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 qemu_malloc/qemu_mallocz/qemu_realloc/qemu_free or > +qemu_vmalloc/qemu_memalign/qemu_vfree APIs. > + > +Memory allocated by qemu_vmalloc or qemu_memalign must be freed with > +qemu_vfree, since breaking this will cause problems on Win32 and user > +emulators. Maybe add that a NULL check for the qemu_malloc result is redundant. And a warning about the stupid qemu_malloc(0) behaviour would be appropriate, too. Because if you don't know it, you'll write buggy code. Kevin