* include/freetype/internal/ftmemory.h, src/base/ftdbgmem.c: modified the debugging memory manager to report the location (source file name + line number) where leaked memory blocks are allocated in the source file.. funny, isn't it ??
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
diff --git a/ChangeLog b/ChangeLog
index 808abd3..0918458 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2001-10-22 David Turner <david@freetype.org>
+ * include/freetype/internal/ftmemory.h, src/base/ftdbgmem.c: modified
+ the debugging memory manager to report the location (source file name
+ + line number) where leaked memory blocks are allocated in the source
+ file.. funny, isn't it ??
+
* src/base/ftdbgmem.c: new debugging memory manager. You must define
the FT_DEBUG_MEMORY macro in "ftoption.h" to enable it. It will record
every memory block allocated and report simple errors like memory
diff --git a/docs/TODO b/docs/TODO
index c7816a0..76b34fe 100644
--- a/docs/TODO
+++ b/docs/TODO
@@ -5,6 +5,3 @@ Here is a list of items that need to be addressed in FreeType 2; they are
not exactly bugs, but should be considered though:
* Add synthesized Unicode charmap processing to the CFF driver.
-
-* Add the new auto-hinting source code / native Type1/Type2 hinter
- to the source code.
diff --git a/include/freetype/internal/ftmemory.h b/include/freetype/internal/ftmemory.h
index e64865e..1a27e0e 100644
--- a/include/freetype/internal/ftmemory.h
+++ b/include/freetype/internal/ftmemory.h
@@ -55,6 +55,16 @@ FT_BEGIN_HEADER
/*************************************************************************/
/*************************************************************************/
+#ifdef FT_DEBUG_MEMORY
+
+ FT_BASE( FT_Error )
+ FT_Alloc_Debug( FT_Memory memory,
+ FT_Long size,
+ void* *P,
+ const char* file_name,
+ FT_Long line_no );
+#endif
+
/*************************************************************************/
/* */
@@ -83,7 +93,6 @@ FT_BEGIN_HEADER
FT_Long size,
void* *P );
-
/*************************************************************************/
/* */
/* <Function> */
@@ -159,6 +168,7 @@ FT_BEGIN_HEADER
#define MEM_Move( dest, source, count ) memmove( dest, source, count )
+
/*************************************************************************/
/* */
/* We now support closures to produce completely reentrant code. This */
@@ -172,12 +182,26 @@ FT_BEGIN_HEADER
/* ALLOC_ARRAY() now use an implicit variable, `memory'. It must be */
/* defined at all locations where a memory operation is queried. */
/* */
-#define MEM_Alloc( _pointer_, _size_ ) \
- FT_Alloc( memory, _size_, (void**)&(_pointer_) )
-#define MEM_Alloc_Array( _pointer_, _count_, _type_ ) \
- FT_Alloc( memory, (_count_)*sizeof ( _type_ ), \
- (void**)&(_pointer_) )
+#ifdef FT_DEBUG_MEMORY
+
+# define MEM_Alloc( _pointer_, _size_ ) \
+ FT_Alloc_Debug( memory, _size_, (void**)&(_pointer_), __FILE__, __LINE__ )
+
+# define MEM_Alloc_Array( _pointer_, _count_, _type_ ) \
+ FT_Alloc_Debug( memory, (_count_)*sizeof ( _type_ ), \
+ (void**)&(_pointer_), __FILE__, __LINE__ )
+
+#else /* !FT_DEBUG_MEMORY */
+
+# define MEM_Alloc( _pointer_, _size_ ) \
+ FT_Alloc( memory, _size_, (void**)&(_pointer_) )
+
+# define MEM_Alloc_Array( _pointer_, _count_, _type_ ) \
+ FT_Alloc( memory, (_count_)*sizeof ( _type_ ), \
+ (void**)&(_pointer_) )
+
+#endif /* !FT_DEBUG_MEMORY */
#define MEM_Realloc( _pointer_, _current_, _size_ ) \
FT_Realloc( memory, _current_, _size_, (void**)&(_pointer_) )
diff --git a/src/base/ftdbgmem.c b/src/base/ftdbgmem.c
index 35b7b2b..f35aafb 100644
--- a/src/base/ftdbgmem.c
+++ b/src/base/ftdbgmem.c
@@ -20,9 +20,13 @@
typedef struct FT_MemNodeRec_
{
- FT_Byte* address;
- FT_Long size; /* < 0 if the block was freed */
- FT_MemNode link;
+ FT_Byte* address;
+ FT_Long size; /* < 0 if the block was freed */
+
+ const char* file_name;
+ FT_Long line_no;
+
+ FT_MemNode link;
} FT_MemNodeRec;
@@ -36,6 +40,9 @@
FT_ULong alloc_total;
FT_ULong alloc_current;
+ const char* file_name;
+ FT_Long line_no;
+
} FT_MemTableRec;
#define FT_MEM_SIZE_MIN 7
@@ -160,40 +167,6 @@
}
- static FT_MemNode
- ft_mem_node_new( FT_MemTable table,
- FT_Pointer address,
- FT_ULong size )
- {
- FT_MemNode node;
-
- node = malloc( sizeof(*node) );
- if ( node == NULL )
- ft_mem_debug_panic( "not enough memory to run memory tests" );
-
- node->link = NULL;
- node->address = address;
- node->size = size;
-
- return node;
- }
-
-
- static void
- ft_mem_node_destroy( FT_MemNode node,
- FT_MemTable table )
- {
- if (node)
- {
- node->address = NULL;
- node->size = 0;
- node->link = NULL;
-
- free( node );
- }
- }
-
-
static FT_MemTable
ft_mem_table_new( void )
@@ -244,8 +217,10 @@
if ( node->size > 0 )
{
- printf( "leaked memory block at address %p, size %ld\n",
- node->address, node->size );
+ printf( "leaked memory block at address %p, size %8ld (%s:%d)\n",
+ node->address, node->size,
+ node->file_name ? node->file_name : "unknown_file",
+ node->line_no );
leak_count++;
leaks += node->size;
@@ -337,9 +312,13 @@
if ( node == NULL )
ft_mem_debug_panic( "not enough memory to run memory tests" );
- node->address = address;
- node->size = size;
- node->link = pnode[0];
+ node->address = address;
+ node->size = size;
+
+ node->file_name = table->file_name;
+ node->line_no = table->line_no;
+
+ node->link = pnode[0];
pnode[0] = node;
table->nodes++;
@@ -494,6 +473,26 @@
}
}
+
+ FT_BASE_DEF( FT_Error )
+ FT_Alloc_Debug( FT_Memory memory,
+ FT_Long size,
+ void* *P,
+ const char* file_name,
+ FT_Long line_no )
+ {
+ FT_MemTable table = memory->user;
+
+ if ( table )
+ {
+ table->file_name = file_name;
+ table->line_no = line_no;
+ }
+ return FT_Alloc( memory, size, P );
+ }
+
+
+
#else /* !FT_DEBUG_MEMORY */
/* ansi C doesn't like empty source files */