[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] [RFC] qemu_malloc dynamic checking
From: |
Kevin Wolf |
Subject: |
Re: [Qemu-devel] [PATCH] [RFC] qemu_malloc dynamic checking |
Date: |
Wed, 15 Apr 2009 22:41:12 +0200 |
User-agent: |
KMail/1.9.5 |
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 <stdlib.h>
>
> +#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