diff options
author | Ton Roosendaal <ton@blender.org> | 2006-11-27 16:59:55 +0300 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2006-11-27 16:59:55 +0300 |
commit | 6d540b6333b0ab846ae2369e25cd2f0a85175d65 (patch) | |
tree | b69a17bf53f18035044c2f92bb2fbcba0112e006 /intern/guardedalloc | |
parent | 2e0084c2d9bc53adf0a9589e71ed89841d34eb65 (diff) |
More debug goodies:
WINDOWS CRASH EMULATION!
If you use the -d (debug) argument for starting blender, it will now:
- set all freed memory to 0xFFFFFFFF
- set all malloced memory to 0xFFFFFFFF
The first option will give nice crashers when you read from freed memory.
The second option is for OSX especially, it has the nasty habit to give
zeroed mallocs.
Diffstat (limited to 'intern/guardedalloc')
-rw-r--r-- | intern/guardedalloc/MEM_guardedalloc.h | 4 | ||||
-rw-r--r-- | intern/guardedalloc/intern/mallocn.c | 23 |
2 files changed, 22 insertions, 5 deletions
diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h index ce9f2a273bd..26a9258d03b 100644 --- a/intern/guardedalloc/MEM_guardedalloc.h +++ b/intern/guardedalloc/MEM_guardedalloc.h @@ -115,6 +115,10 @@ extern "C" { /** Set thread locking functions for safe memory allocation from multiple threads, pass NULL pointers to disable thread locking again. */ void MEM_set_lock_callback(void (*lock)(void), void (*unlock)(void)); + + /** Attempt to enforce OSX (or other OS's) to have malloc and stack nonzero */ + void MEM_set_memory_debug(void); + #ifdef __cplusplus } diff --git a/intern/guardedalloc/intern/mallocn.c b/intern/guardedalloc/intern/mallocn.c index 77184ac9370..51c2a2427b5 100644 --- a/intern/guardedalloc/intern/mallocn.c +++ b/intern/guardedalloc/intern/mallocn.c @@ -120,6 +120,8 @@ static void (*error_callback)(char *) = NULL; static void (*thread_lock_callback)(void) = NULL; static void (*thread_unlock_callback)(void) = NULL; +static int malloc_debug_memset= 0; + #ifdef malloc #undef malloc #endif @@ -187,6 +189,11 @@ void MEM_set_lock_callback(void (*lock)(void), void (*unlock)(void)) thread_unlock_callback = unlock; } +void MEM_set_memory_debug(void) +{ + malloc_debug_memset= 1; +} + int MEM_allocN_len(void *vmemh) { if (vmemh) { @@ -253,6 +260,8 @@ void *MEM_mallocN(unsigned int len, const char *str) if(memh) { make_memhead_header(memh, len, str); mem_unlock_thread(); + if(malloc_debug_memset && len) + memset(memh+1, 255, len); return (++memh); } mem_unlock_thread(); @@ -447,10 +456,11 @@ static void remlink(volatile localListBase *listbase, void *vlink) static void rem_memblock(MemHead *memh) { remlink(membase,&memh->next); - if (memh->prev){ - if (memh->next) MEMNEXT(memh->prev)->nextname = -MEMNEXT(memh->next)->name; - else MEMNEXT(memh->prev)->nextname = 0; + if (memh->prev) { + if (memh->next) + MEMNEXT(memh->prev)->nextname = MEMNEXT(memh->next)->name; + else + MEMNEXT(memh->prev)->nextname = NULL; } totblock--; @@ -465,8 +475,11 @@ MEMNEXT(memh->next)->name; if (munmap(memh, memh->len + sizeof(MemHead) + sizeof(MemTail))) printf("Couldn't unmap memory %s\n", memh->name); } - else + else { + if(malloc_debug_memset && memh->len) + memset(memh+1, 255, memh->len); free(memh); + } #endif } |