From f2c9e2fbd251736b50f88cea07e8a97635b5c6fa Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 19 Sep 2013 23:07:36 +0000 Subject: Add calloc() support to memory leak finder. --- lib/common/DebugMemLeakFinder.cpp | 10 ++++++++++ lib/common/MemLeakFinder.h | 2 ++ lib/common/Utils.cpp | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) 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; } -- cgit v1.2.3