forked from bartvdbraak/blender
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.
This commit is contained in:
parent
2e0084c2d9
commit
6d540b6333
@ -116,6 +116,10 @@ extern "C" {
|
||||
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
|
||||
}
|
||||
#endif
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user