Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LuBvg-0000dP-WD for qemu-devel@nongnu.org; Wed, 15 Apr 2009 16:41:57 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LuBvc-0000cT-B3 for qemu-devel@nongnu.org; Wed, 15 Apr 2009 16:41:56 -0400 Received: from [199.232.76.173] (port=37794 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LuBvc-0000cQ-3M for qemu-devel@nongnu.org; Wed, 15 Apr 2009 16:41:52 -0400 Received: from mo-p00-ob.rzone.de ([81.169.146.162]:11967) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LuBvb-00075D-J8 for qemu-devel@nongnu.org; Wed, 15 Apr 2009 16:41:51 -0400 Received: from nepun.site (Rac27.r.pppool.de [89.54.172.39]) by post.strato.de (mrclete mo5) (RZmta 18.28) with ESMTP id Y02177l3FJSXOm for ; Wed, 15 Apr 2009 22:41:48 +0200 (MEST) From: Kevin Wolf Subject: Re: [Qemu-devel] [PATCH] [RFC] qemu_malloc dynamic checking Date: Wed, 15 Apr 2009 22:41:12 +0200 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200904152241.12595@kevin-wolf.de> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Am Mittwoch, 15. April 2009 20:23 schrieb Blue Swirl: > This patch adds simple checks for qemu_malloc/free/realloc. With the > check enabled, i386-softmmu crashes. Sparc32, Sparc64, PPC32 and PPC64 > system emulators are fine. Generally I like the idea of running this kind of tests occasionally. I'm wondering though if we really need additional code for it, or if using external tools like valgrind could do the same without additional code and with the extra bonus of actually telling you who the culprit was. > Index: qemu/qemu-malloc.c > =================================================================== > --- qemu.orig/qemu-malloc.c 2009-04-15 17:16:44.000000000 +0000 > +++ qemu/qemu-malloc.c 2009-04-15 18:09:49.000000000 +0000 > @@ -24,6 +24,11 @@ > #include "qemu-common.h" > #include > > +#define DEBUG_MALLOC > + > +/* Canary must not break malloc alignment */ > +static const char canary[] = "QEMU_MALLOC1234"; > + > static void *oom_check(void *ptr) > { > if (ptr == NULL) > @@ -38,20 +43,58 @@ > > void qemu_free(void *ptr) > { > +#ifdef DEBUG_MALLOC > + fprintf(stderr, "qemu_free: 0x%p\n", ptr); > + if (ptr) { > + ptr = (void *)((unsigned long)ptr - sizeof(canary)); > + if (memcmp(ptr, canary, sizeof(canary)) != 0) { > + exit(0); I'm used to the convention that an exit code of 0 means success. abort() might be the right thing here. Kevin