[PATCH] (gmem.c) ENABLE_MEM_CHECK bug
- From: Martin Pool <mbp wistful humbug org au>
- To: otaylor redhat com
- Cc: gtk-devel-list redhat com
- Subject: [PATCH] (gmem.c) ENABLE_MEM_CHECK bug
- Date: Sat, 22 Aug 1998 15:35:19 +1000
Attached is a tiny patch to fix a bug that causes g_malloc0 to break
its invariants when ENABLE_MEM_CHECK is defined and ENABLE_MEM_PROFILE
is not. The bug causes a coredump in testglib.c using the glib-1.1.2
source.
--
Martin Pool
*** gmem.c.~1~ Thu Jun 11 09:21:13 1998
--- gmem.c Sat Aug 22 15:28:45 1998
***************
*** 1,6 ****
/* GLIB - Library of useful routines for C programming
! * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
--- 1,6 ----
/* GLIB - Library of useful routines for C programming
! * Copyright (C) 1995-1998 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
***************
*** 22,29 ****
--- 22,45 ----
/* #define ENABLE_MEM_PROFILE */
/* #define ENABLE_MEM_CHECK */
+ /*
+ * This library can check for some attempts to do illegal things to
+ * memory (ENABLE_MEM_CHECK), and can do profiling
+ * (ENABLE_MEM_PROFILE). Both features are implemented by storing
+ * words before the start of the memory chunk.
+ *
+ * The first, at offset -2*SIZEOF_LONG, is used only if
+ * ENABLE_MEM_CHECK is set, and stores 0 after the memory has been
+ * allocated and 1 when it has been freed. The second, at offset
+ * -SIZEOF_LONG, is used if either flag is set and stores the size of
+ * the block.
+ *
+ * The MEM_CHECK flag is checked when memory is realloc'd and free'd,
+ * and it can be explicitly checked before using a block by calling
+ * g_mem_check().
+ */
#define MAX_MEM_AREA 65536L
#define MEM_AREA_SIZE 4L
***************
*** 167,175 ****
if (size == 0)
return NULL;
! #ifdef ENABLE_MEM_PROFILE
size += SIZEOF_LONG;
#endif /* ENABLE_MEM_PROFILE */
#ifdef ENABLE_MEM_CHECK
--- 183,191 ----
if (size == 0)
return NULL;
! #if defined(ENABLE_MEM_PROFILE) || defined(ENABLE_MEM_CHECK)
size += SIZEOF_LONG;
#endif /* ENABLE_MEM_PROFILE */
#ifdef ENABLE_MEM_CHECK
***************
*** 350,358 ****
t = (gulong*) ((guchar*) mem - SIZEOF_LONG - SIZEOF_LONG);
if (*t >= 1)
! g_warning ("mem: 0x%08x has been freed: %lu\n", (gulong) mem, *t);
#endif /* ENABLE_MEM_CHECK */
}
GMemChunk*
--- 366,374 ----
t = (gulong*) ((guchar*) mem - SIZEOF_LONG - SIZEOF_LONG);
if (*t >= 1)
! g_warning ("mem: 0x%p has been freed: %lu\n", mem, *t);
#endif /* ENABLE_MEM_CHECK */
}
GMemChunk*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]