summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/HPM.c2
-rw-r--r--src/common/Makefile.in8
-rw-r--r--src/common/console.c2
-rw-r--r--src/common/core.c2
-rw-r--r--src/common/db.c2
-rw-r--r--src/common/ers.c2
-rw-r--r--src/common/grfio.c2
-rw-r--r--src/common/memmgr.c (renamed from src/common/malloc.c)52
-rw-r--r--src/common/memmgr.h (renamed from src/common/malloc.h)0
-rw-r--r--src/common/mutex.c2
-rw-r--r--src/common/socket.c2
-rw-r--r--src/common/sql.c2
-rw-r--r--src/common/strlib.c2
-rw-r--r--src/common/sysinfo.c2
-rw-r--r--src/common/thread.c2
-rw-r--r--src/common/timer.c2
16 files changed, 67 insertions, 19 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index 5373c8b6a..7d9a0b104 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -11,7 +11,7 @@
#include "common/console.h"
#include "common/core.h"
#include "common/db.h"
-#include "common/malloc.h"
+#include "common/memmgr.h"
#include "common/mapindex.h"
#include "common/mmo.h"
#include "common/showmsg.h"
diff --git a/src/common/Makefile.in b/src/common/Makefile.in
index 208d3b111..88e991651 100644
--- a/src/common/Makefile.in
+++ b/src/common/Makefile.in
@@ -27,12 +27,12 @@ COMMON_SHARED_C = conf.c db.c des.c ers.c grfio.c HPM.c mapindex.c md5calc.c \
COMMON_C = $(COMMON_SHARED_C)
COMMON_SHARED_OBJ = $(patsubst %.c,%.o,$(COMMON_SHARED_C))
COMMON_OBJ = $(addprefix obj_all/, $(COMMON_SHARED_OBJ) \
- console.o core.o malloc.o socket.o)
+ console.o core.o memmgr.o socket.o)
COMMON_MINI_OBJ = $(addprefix obj_all/, $(COMMON_SHARED_OBJ) \
- miniconsole.o minicore.o minimalloc.o minisocket.o)
-COMMON_C += console.c core.c malloc.c socket.c
+ miniconsole.o minicore.o minimemmgr.o minisocket.o)
+COMMON_C += console.c core.c memmgr.c socket.c
COMMON_H = atomic.h cbasetypes.h conf.h console.h core.h db.h des.h ers.h \
- grfio.h hercules.h HPM.h HPMi.h malloc.h mapindex.h md5calc.h \
+ grfio.h hercules.h HPM.h HPMi.h memmgr.h mapindex.h md5calc.h \
mmo.h mutex.h nullpo.h random.h showmsg.h socket.h spinlock.h \
sql.h strlib.h sysinfo.h thread.h timer.h utils.h winapi.h
diff --git a/src/common/console.c b/src/common/console.c
index c8ca4ae87..f4f18b799 100644
--- a/src/common/console.c
+++ b/src/common/console.c
@@ -16,7 +16,7 @@
#ifndef MINICORE
# include "common/atomic.h"
# include "common/ers.h"
-# include "common/malloc.h"
+# include "common/memmgr.h"
# include "common/mutex.h"
# include "common/spinlock.h"
# include "common/sql.h"
diff --git a/src/common/core.c b/src/common/core.c
index 8564b8acc..6f21f526b 100644
--- a/src/common/core.c
+++ b/src/common/core.c
@@ -10,7 +10,7 @@
#include "common/cbasetypes.h"
#include "common/console.h"
#include "common/db.h"
-#include "common/malloc.h"
+#include "common/memmgr.h"
#include "common/mmo.h"
#include "common/random.h"
#include "common/showmsg.h"
diff --git a/src/common/db.c b/src/common/db.c
index 4df5c08db..0600be2e8 100644
--- a/src/common/db.c
+++ b/src/common/db.c
@@ -73,7 +73,7 @@
#include "db.h"
#include "common/ers.h"
-#include "common/malloc.h"
+#include "common/memmgr.h"
#include "common/mmo.h"
#include "common/showmsg.h"
#include "common/strlib.h"
diff --git a/src/common/ers.c b/src/common/ers.c
index 91fc6ccfb..bf17e087d 100644
--- a/src/common/ers.c
+++ b/src/common/ers.c
@@ -45,7 +45,7 @@
#include "ers.h"
#include "common/cbasetypes.h"
-#include "common/malloc.h" // CREATE, RECREATE, aMalloc, aFree
+#include "common/memmgr.h" // CREATE, RECREATE, aMalloc, aFree
#include "common/nullpo.h"
#include "common/showmsg.h" // ShowMessage, ShowError, ShowFatalError, CL_BOLD, CL_NORMAL
diff --git a/src/common/grfio.c b/src/common/grfio.c
index b59c2b63d..46804ea08 100644
--- a/src/common/grfio.c
+++ b/src/common/grfio.c
@@ -8,7 +8,7 @@
#include "common/cbasetypes.h"
#include "common/des.h"
-#include "common/malloc.h"
+#include "common/memmgr.h"
#include "common/nullpo.h"
#include "common/showmsg.h"
#include "common/strlib.h"
diff --git a/src/common/malloc.c b/src/common/memmgr.c
index 63de90cb3..0d9305b06 100644
--- a/src/common/malloc.c
+++ b/src/common/memmgr.c
@@ -4,7 +4,7 @@
#define HERCULES_CORE
-#include "malloc.h"
+#include "memmgr.h"
#include "common/cbasetypes.h"
#include "common/core.h"
@@ -79,6 +79,26 @@ struct malloc_interface *iMalloc;
#endif
+#ifndef USE_MEMMGR
+
+#ifdef __APPLE__
+#include <malloc/malloc.h>
+#define BUFFER_SIZE(ptr) malloc_size(ptr)
+#elif __FreeBSD__
+#include <malloc_np.h>
+#define BUFFER_SIZE(ptr) malloc_usable_size(ptr)
+#elif defined __linux__ || defined __linux || defined CYGWIN
+#include <malloc.h>
+#define BUFFER_SIZE(ptr) malloc_usable_size(ptr)
+#elif defined WIN32
+#include <malloc.h>
+#define BUFFER_SIZE(ptr) _msize(ptr)
+#else
+#error Unsupported OS
+#endif
+
+#endif
+
void* aMalloc_(size_t size, const char *file, int line, const char *func)
{
void *ret = MALLOC(size, file, line, func);
@@ -110,6 +130,34 @@ void* aRealloc_(void *p, size_t size, const char *file, int line, const char *fu
}
return ret;
}
+
+void* aReallocz_(void *p, size_t size, const char *file, int line, const char *func)
+{
+ void *ret;
+ // ShowMessage("%s:%d: in func %s: aReallocz %p %ld\n",file,line,func,p,size);
+#ifdef USE_MEMMGR
+ ret = REALLOC(p, size, file, line, func);
+#else
+ size_t newSize;
+ if (p) {
+ size_t oldSize = malloc_usable_size(p);
+ ret = REALLOC(p, size, file, line, func);
+ newSize = BUFFER_SIZE(ret);
+ if (ret && newSize > oldSize)
+ memset(ret + oldSize, 0, newSize - oldSize);
+ } else {
+ ret = REALLOC(p, size, file, line, func);
+ if (ret)
+ memset(ret, 0, BUFFER_SIZE(ret));
+ }
+#endif
+ if (ret == NULL){
+ ShowFatalError("%s:%d: in func %s: aRealloc error out of memory!\n",file,line,func);
+ exit(EXIT_FAILURE);
+ }
+ return ret;
+}
+
char* aStrdup_(const char *p, const char *file, int line, const char *func)
{
char *ret = STRDUP(p, file, line, func);
@@ -888,7 +936,7 @@ void malloc_defaults(void) {
iMalloc->malloc = aMalloc_;
iMalloc->calloc = aCalloc_;
iMalloc->realloc = aRealloc_;
- iMalloc->reallocz = aRealloc_;/* not using memory manager huhum o.o perhaps we could still do something about */
+ iMalloc->reallocz = aReallocz_;/* not using memory manager huhum o.o perhaps we could still do something about */
iMalloc->astrdup = aStrdup_;
iMalloc->free = aFree_;
#endif
diff --git a/src/common/malloc.h b/src/common/memmgr.h
index b194c7cf3..b194c7cf3 100644
--- a/src/common/malloc.h
+++ b/src/common/memmgr.h
diff --git a/src/common/mutex.c b/src/common/mutex.c
index 715609628..af1a6d155 100644
--- a/src/common/mutex.c
+++ b/src/common/mutex.c
@@ -6,7 +6,7 @@
#include "mutex.h"
#include "common/cbasetypes.h" // for WIN32
-#include "common/malloc.h"
+#include "common/memmgr.h"
#include "common/showmsg.h"
#include "common/timer.h"
diff --git a/src/common/socket.c b/src/common/socket.c
index b4b67da40..b418a468f 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -10,7 +10,7 @@
#include "common/HPM.h"
#include "common/cbasetypes.h"
#include "common/db.h"
-#include "common/malloc.h"
+#include "common/memmgr.h"
#include "common/mmo.h"
#include "common/nullpo.h"
#include "common/showmsg.h"
diff --git a/src/common/sql.c b/src/common/sql.c
index ee759eb61..4262a10a1 100644
--- a/src/common/sql.c
+++ b/src/common/sql.c
@@ -7,7 +7,7 @@
#include "sql.h"
#include "common/cbasetypes.h"
-#include "common/malloc.h"
+#include "common/memmgr.h"
#include "common/showmsg.h"
#include "common/strlib.h"
#include "common/timer.h"
diff --git a/src/common/strlib.c b/src/common/strlib.c
index fcd1b483b..fefabe52b 100644
--- a/src/common/strlib.c
+++ b/src/common/strlib.c
@@ -7,7 +7,7 @@
#include "strlib.h"
#include "common/cbasetypes.h"
-#include "common/malloc.h"
+#include "common/memmgr.h"
#include "common/showmsg.h"
#include <errno.h>
diff --git a/src/common/sysinfo.c b/src/common/sysinfo.c
index d218e6e99..1baf33086 100644
--- a/src/common/sysinfo.c
+++ b/src/common/sysinfo.c
@@ -10,7 +10,7 @@
#include "common/cbasetypes.h"
#include "common/core.h"
-#include "common/malloc.h"
+#include "common/memmgr.h"
#include "common/strlib.h"
#include <stdio.h> // fopen
diff --git a/src/common/thread.c b/src/common/thread.c
index d5bbd7f97..d9cd42aa6 100644
--- a/src/common/thread.c
+++ b/src/common/thread.c
@@ -11,7 +11,7 @@
#include "thread.h"
#include "common/cbasetypes.h"
-#include "common/malloc.h"
+#include "common/memmgr.h"
#include "common/showmsg.h"
#include "common/sysinfo.h" // sysinfo->getpagesize()
diff --git a/src/common/timer.c b/src/common/timer.c
index f6ce00d54..f31ae0ffe 100644
--- a/src/common/timer.c
+++ b/src/common/timer.c
@@ -8,7 +8,7 @@
#include "common/cbasetypes.h"
#include "common/db.h"
-#include "common/malloc.h"
+#include "common/memmgr.h"
#include "common/showmsg.h"
#include "common/utils.h"