gallium: Allow to debug memory leaks in nested scopes.

This commit is contained in:
José Fonseca
2008-04-08 11:30:36 +09:00
parent 985134211d
commit 4e2127b0e5
2 changed files with 11 additions and 11 deletions

View File

@@ -70,8 +70,7 @@ struct debug_memory_header
static struct list_head list = { &list, &list }; static struct list_head list = { &list, &list };
static unsigned long start_no = 0; static unsigned long last_no = 0;
static unsigned long end_no = 0;
void * void *
@@ -84,7 +83,7 @@ debug_malloc(const char *file, unsigned line, const char *function,
if(!hdr) if(!hdr)
return NULL; return NULL;
hdr->no = end_no++; hdr->no = last_no++;
hdr->file = file; hdr->file = file;
hdr->line = line; hdr->line = line;
hdr->function = function; hdr->function = function;
@@ -147,14 +146,14 @@ debug_realloc(const char *file, unsigned line, const char *function,
return new_ptr; return new_ptr;
} }
void unsigned long
debug_memory_reset(void) debug_memory_begin(void)
{ {
start_no = end_no; return last_no;
} }
void void
debug_memory_report(void) debug_memory_end(unsigned long start_no)
{ {
struct list_head *entry; struct list_head *entry;
@@ -164,7 +163,8 @@ debug_memory_report(void)
void *ptr; void *ptr;
hdr = LIST_ENTRY(struct debug_memory_header, entry, head); hdr = LIST_ENTRY(struct debug_memory_header, entry, head);
ptr = (void *)((char *)hdr + sizeof(*hdr)); ptr = (void *)((char *)hdr + sizeof(*hdr));
if(hdr->no >= start_no) if(start_no <= hdr->no && hdr->no < last_no ||
last_no < start_no && (hdr->no < last_no || start_no <= hdr->no))
debug_printf("%s:%u:%s: %u bytes at %p not freed\n", debug_printf("%s:%u:%s: %u bytes at %p not freed\n",
hdr->file, hdr->line, hdr->function, hdr->file, hdr->line, hdr->function,
hdr->size, ptr); hdr->size, ptr);

View File

@@ -304,11 +304,11 @@ void *
debug_realloc(const char *file, unsigned line, const char *function, debug_realloc(const char *file, unsigned line, const char *function,
void *old_ptr, size_t old_size, size_t new_size ); void *old_ptr, size_t old_size, size_t new_size );
void unsigned long
debug_memory_reset(void); debug_memory_begin(void);
void void
debug_memory_report(void); debug_memory_end(unsigned long beginning);
#ifdef __cplusplus #ifdef __cplusplus