diff options
author | Chris Wilson <chris+github@qwirx.com> | 2013-09-19 23:07:36 +0000 |
---|---|---|
committer | Chris Wilson <chris+github@qwirx.com> | 2013-09-19 23:07:36 +0000 |
commit | f2c9e2fbd251736b50f88cea07e8a97635b5c6fa (patch) | |
tree | 5ec1dc3e8f841a526a9fed256d03b3f5d259ad7f | |
parent | 93966139dbfc1ee289718087c4a232dd44d337f7 (diff) |
Add calloc() support to memory leak finder.
-rw-r--r-- | lib/common/DebugMemLeakFinder.cpp | 10 | ||||
-rw-r--r-- | lib/common/MemLeakFinder.h | 2 | ||||
-rw-r--r-- | lib/common/Utils.cpp | 2 |
3 files changed, 13 insertions, 1 deletions
diff --git a/lib/common/DebugMemLeakFinder.cpp b/lib/common/DebugMemLeakFinder.cpp index a4f8d41e..0b123675 100644 --- a/lib/common/DebugMemLeakFinder.cpp +++ b/lib/common/DebugMemLeakFinder.cpp @@ -164,6 +164,16 @@ void *memleakfinder_malloc(size_t size, const char *file, int line) return b; } +void *memleakfinder_calloc(size_t blocks, size_t size, const char *file, int line) +{ + void *block = memleakfinder_malloc(blocks * size, file, line); + if (block != 0) + { + memset(block, 0, blocks * size); + } + return block; +} + void *memleakfinder_realloc(void *ptr, size_t size) { InternalAllocGuard guard; diff --git a/lib/common/MemLeakFinder.h b/lib/common/MemLeakFinder.h index 91c93217..1a2cf90c 100644 --- a/lib/common/MemLeakFinder.h +++ b/lib/common/MemLeakFinder.h @@ -28,6 +28,7 @@ class MemLeakSuppressionGuard extern "C" { void *memleakfinder_malloc(size_t size, const char *file, int line); + void *memleakfinder_calloc(size_t blocks, size_t size, const char *file, int line); void *memleakfinder_realloc(void *ptr, size_t size); void memleakfinder_free(void *ptr); } @@ -56,6 +57,7 @@ void *operator new[](size_t size, const char *file, int line); // define the malloc functions now, if required #ifdef MEMLEAKFINDER_FULL_MALLOC_MONITORING #define malloc(X) memleakfinder_malloc(X, __FILE__, __LINE__) + #define calloc(X, Y) memleakfinder_calloc(X, Y, __FILE__, __LINE__) #define realloc memleakfinder_realloc #define free memleakfinder_free #define MEMLEAKFINDER_MALLOC_MONITORING_DEFINED diff --git a/lib/common/Utils.cpp b/lib/common/Utils.cpp index 51bc3040..decc80e8 100644 --- a/lib/common/Utils.cpp +++ b/lib/common/Utils.cpp @@ -132,7 +132,7 @@ static std::string demangle(const std::string& mangled_name) { std::string output = result; #include "MemLeakFindOff.h" - std::free(result); + free(result); #include "MemLeakFindOn.h" return output; } |