Fortify memory debugging.
These changes are neccessary to properly recover `memory->user` that holds the Windows heap handle now. * src/base/ftdbgmem.c (ft_mem_debug_init): Handle all table allocations, initializations, and sizing instead of... (ft_mem_table_new): ... this function removed. (ft_mem_debug_done): Better check for the active debugger and free the debugger table here instead of... (ft_mem_table_destroy): ... here.
This commit is contained in:
parent
77dcc5ed6a
commit
63806aad9f
|
@ -302,46 +302,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static FT_MemTable
|
|
||||||
ft_mem_table_new( FT_Memory memory )
|
|
||||||
{
|
|
||||||
FT_MemTable table;
|
|
||||||
|
|
||||||
|
|
||||||
table = (FT_MemTable)memory->alloc( memory, sizeof ( *table ) );
|
|
||||||
if ( !table )
|
|
||||||
goto Exit;
|
|
||||||
|
|
||||||
FT_ZERO( table );
|
|
||||||
|
|
||||||
table->size = FT_MEM_SIZE_MIN;
|
|
||||||
table->nodes = 0;
|
|
||||||
|
|
||||||
table->memory = memory;
|
|
||||||
|
|
||||||
table->memory_user = memory->user;
|
|
||||||
|
|
||||||
table->alloc = memory->alloc;
|
|
||||||
table->realloc = memory->realloc;
|
|
||||||
table->free = memory->free;
|
|
||||||
|
|
||||||
table->buckets = (FT_MemNode *)
|
|
||||||
memory->alloc(
|
|
||||||
memory,
|
|
||||||
table->size * (FT_Long)sizeof ( FT_MemNode ) );
|
|
||||||
if ( table->buckets )
|
|
||||||
FT_ARRAY_ZERO( table->buckets, table->size );
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memory->free( memory, table );
|
|
||||||
table = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Exit:
|
|
||||||
return table;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ft_mem_table_destroy( FT_MemTable table )
|
ft_mem_table_destroy( FT_MemTable table )
|
||||||
{
|
{
|
||||||
|
@ -413,8 +373,6 @@
|
||||||
printf( "FreeType: maximum memory footprint = %ld\n",
|
printf( "FreeType: maximum memory footprint = %ld\n",
|
||||||
table->alloc_max );
|
table->alloc_max );
|
||||||
|
|
||||||
ft_mem_table_free( table, table );
|
|
||||||
|
|
||||||
if ( leak_count > 0 )
|
if ( leak_count > 0 )
|
||||||
ft_mem_debug_panic(
|
ft_mem_debug_panic(
|
||||||
"FreeType: %ld bytes of memory leaked in %ld blocks\n",
|
"FreeType: %ld bytes of memory leaked in %ld blocks\n",
|
||||||
|
@ -821,17 +779,30 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern FT_Int
|
extern void
|
||||||
ft_mem_debug_init( FT_Memory memory )
|
ft_mem_debug_init( FT_Memory memory )
|
||||||
{
|
{
|
||||||
FT_MemTable table;
|
FT_MemTable table;
|
||||||
FT_Int result = 0;
|
|
||||||
|
|
||||||
|
|
||||||
if ( ft_getenv( "FT2_DEBUG_MEMORY" ) )
|
if ( !ft_getenv( "FT2_DEBUG_MEMORY" ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
table = (FT_MemTable)memory->alloc( memory, sizeof ( *table ) );
|
||||||
|
|
||||||
|
if ( table )
|
||||||
{
|
{
|
||||||
table = ft_mem_table_new( memory );
|
FT_ZERO( table );
|
||||||
if ( table )
|
|
||||||
|
table->memory = memory;
|
||||||
|
table->memory_user = memory->user;
|
||||||
|
table->alloc = memory->alloc;
|
||||||
|
table->realloc = memory->realloc;
|
||||||
|
table->free = memory->free;
|
||||||
|
|
||||||
|
ft_mem_table_resize( table );
|
||||||
|
|
||||||
|
if ( table->size )
|
||||||
{
|
{
|
||||||
const char* p;
|
const char* p;
|
||||||
|
|
||||||
|
@ -876,28 +847,29 @@
|
||||||
if ( keep_alive > 0 )
|
if ( keep_alive > 0 )
|
||||||
table->keep_alive = 1;
|
table->keep_alive = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = 1;
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
memory->free( memory, table );
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
ft_mem_debug_done( FT_Memory memory )
|
ft_mem_debug_done( FT_Memory memory )
|
||||||
{
|
{
|
||||||
FT_MemTable table = (FT_MemTable)memory->user;
|
if ( memory->free == ft_mem_debug_free )
|
||||||
|
|
||||||
|
|
||||||
if ( table )
|
|
||||||
{
|
{
|
||||||
|
FT_MemTable table = (FT_MemTable)memory->user;
|
||||||
|
|
||||||
|
|
||||||
|
ft_mem_table_destroy( table );
|
||||||
|
|
||||||
memory->free = table->free;
|
memory->free = table->free;
|
||||||
memory->realloc = table->realloc;
|
memory->realloc = table->realloc;
|
||||||
memory->alloc = table->alloc;
|
memory->alloc = table->alloc;
|
||||||
|
memory->user = table->memory_user;
|
||||||
|
|
||||||
ft_mem_table_destroy( table );
|
memory->free( memory, table );
|
||||||
memory->user = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue