* Made the memory manager set allocated memory to 0xCD and freed memory to 0xDD. The memory manager no longer 'hides' uses of freed memory.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@11994 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
FlavioJS 2007-12-30 05:43:51 +00:00
parent 4c54d4923f
commit 382233178c
2 changed files with 22 additions and 1 deletions

View File

@ -3,8 +3,11 @@ Date Added
AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO INTO TRUNK.
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
2007/12/30
* Made the memory manager set allocated memory to 0xCD and freed memory
to 0xDD. The memory manager no longer 'hides' uses of freed memory.
2007/12/29
* Fixed two missing @LDFLAGS@ in src/plugins/Makefile.in. [FlavioJS]
* Implemented THE official Steal skill equation and game mechanics
(basically version from /stable plus a few tweaks) (see topic:116540)
* Added missing bAddStealRate reference to doc/item_bonus.txt

View File

@ -112,6 +112,8 @@ char* _bstrdup(const char *chr)
#ifdef USE_MEMMGR
#define DEBUG_MEMMGR
/* USE_MEMMGR */
/*
@ -226,6 +228,10 @@ void* _mmalloc(size_t size, const char *file, int line, const char *func )
p->next = unit_head_large_first;
}
unit_head_large_first = p;
#ifdef DEBUG_MEMMGR
// set allocated data to 0xCD (clean memory)
memset(p + sizeof(struct unit_head_large) - sizeof(int), 0xCD, size);
#endif
*(int*)((char*)p + sizeof(struct unit_head_large) - sizeof(int) + size) = 0xdeadbeaf;
return (char *)p + sizeof(struct unit_head_large) - sizeof(int);
} else {
@ -284,6 +290,10 @@ void* _mmalloc(size_t size, const char *file, int line, const char *func )
head->size = size;
head->line = line;
head->file = file;
#ifdef DEBUG_MEMMGR
// set allocated memory to 0xCD (clean memory)
memset(head + sizeof(struct unit_head) - sizeof(int), 0xCD, size);
#endif
*(int*)((char*)head + sizeof(struct unit_head) - sizeof(int) + size) = 0xdeadbeaf;
return (char *)head + sizeof(struct unit_head) - sizeof(int);
}
@ -367,6 +377,10 @@ void _mfree(void *ptr, const char *file, int line, const char *func )
}
head->block = NULL;
memmgr_usage_bytes -= head->size;
#ifdef DEBUG_MEMMGR
// set freed memory to 0xDD (dead memory)
memset(ptr, 0xDD, size_hash - sizeof(struct unit_head_large) + sizeof(int) );
#endif
FREE(head_large,file,line,func);
} else {
ShowError("Memory manager: args of aFree is freed pointer %s:%d@%s\n", file, line, func);
@ -382,6 +396,10 @@ void _mfree(void *ptr, const char *file, int line, const char *func )
ShowError("Memory manager: args of aFree is overflowed pointer %s line %d\n", file, line);
} else {
head->block = NULL;
#ifdef DEBUG_MEMMGR
// set freed memory to 0xDD (dead memory)
memset(ptr, 0xDD, block->unit_size - sizeof(struct unit_head) + sizeof(int) );
#endif
memmgr_usage_bytes -= head->size;
if(--block->unit_used == 0) {
/* ƒuƒ<75>ƒbƒN̉ð•ú */