summaryrefslogtreecommitdiff
path: root/src/common/malloc.c
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-30 05:43:51 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2007-12-30 05:43:51 +0000
commit553178680fbdaacbdcf5e8d8d4c2a657362839c2 (patch)
tree9effd674f86d3818ab9276d38fa451db6ea8c8f9 /src/common/malloc.c
parenta2b44a8872f55a3afe16ad20682bbc4f6c685a87 (diff)
downloadhercules-553178680fbdaacbdcf5e8d8d4c2a657362839c2.tar.gz
hercules-553178680fbdaacbdcf5e8d8d4c2a657362839c2.tar.bz2
hercules-553178680fbdaacbdcf5e8d8d4c2a657362839c2.tar.xz
hercules-553178680fbdaacbdcf5e8d8d4c2a657362839c2.zip
* 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://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11994 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/malloc.c')
-rw-r--r--src/common/malloc.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/common/malloc.c b/src/common/malloc.c
index a65ee7eed..70d6f89af 100644
--- a/src/common/malloc.c
+++ b/src/common/malloc.c
@@ -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) {
/* ブロックの解放 */