summaryrefslogtreecommitdiff
path: root/lib/common/DebugMemLeakFinder.cpp
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2007-03-04 23:06:18 +0000
committerChris Wilson <chris+github@qwirx.com>2007-03-04 23:06:18 +0000
commite59d7dac529849bdb8f2c19b2134ac937c5fc325 (patch)
tree6f2caaf4a31a3e6c009010484c1d4545643066dc /lib/common/DebugMemLeakFinder.cpp
parent66812fbfd051698922970220cfa9cfc0db7dbc40 (diff)
Watch out for our leak tracking data being destroyed and don't crash when
subsequent objects are destroyed. (refs #3, merges [1341])
Diffstat (limited to 'lib/common/DebugMemLeakFinder.cpp')
-rw-r--r--lib/common/DebugMemLeakFinder.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/common/DebugMemLeakFinder.cpp b/lib/common/DebugMemLeakFinder.cpp
index fbc684e8..a99b2072 100644
--- a/lib/common/DebugMemLeakFinder.cpp
+++ b/lib/common/DebugMemLeakFinder.cpp
@@ -49,6 +49,17 @@ namespace
{
static std::map<void *, MallocBlockInfo> sMallocBlocks;
static std::map<void *, ObjectInfo> sObjectBlocks;
+ static bool sTrackingDataDestroyed = false;
+
+ static class DestructionWatchdog
+ {
+ public:
+ ~DestructionWatchdog()
+ {
+ sTrackingDataDestroyed = true;
+ }
+ }
+ sWatchdog;
static bool sTrackMallocInSection = false;
static std::set<void *> sSectionMallocBlocks;
@@ -225,6 +236,8 @@ void memleakfinder_notaleak(void *ptr)
{
InternalAllocGuard guard;
+ ASSERT(!sTrackingDataDestroyed);
+
memleakfinder_notaleak_insert_pre();
if(memleakfinder_global_enable && memleakfinder_initialised)
{
@@ -258,6 +271,8 @@ void memleakfinder_startsectionmonitor()
InternalAllocGuard guard;
ASSERT(memleakfinder_initialised);
+ ASSERT(!sTrackingDataDestroyed);
+
sTrackMallocInSection = true;
sSectionMallocBlocks.clear();
sTrackObjectsInSection = true;
@@ -270,6 +285,7 @@ void memleakfinder_traceblocksinsection()
InternalAllocGuard guard;
ASSERT(memleakfinder_initialised);
+ ASSERT(!sTrackingDataDestroyed);
std::set<void *>::iterator s(sSectionMallocBlocks.begin());
for(; s != sSectionMallocBlocks.end(); ++s)
@@ -295,6 +311,7 @@ int memleakfinder_numleaks()
InternalAllocGuard guard;
ASSERT(memleakfinder_initialised);
+ ASSERT(!sTrackingDataDestroyed);
int n = 0;
@@ -316,6 +333,8 @@ void memleakfinder_reportleaks_file(FILE *file)
{
InternalAllocGuard guard;
+ ASSERT(!sTrackingDataDestroyed);
+
for(std::map<void *, MallocBlockInfo>::const_iterator i(sMallocBlocks.begin()); i != sMallocBlocks.end(); ++i)
{
if(is_leak(i->first)) ::fprintf(file, "Block 0x%p size %d allocated at %s:%d\n", i->first, i->second.size, i->second.file, i->second.line);
@@ -388,6 +407,7 @@ void add_object_block(void *block, size_t size, const char *file, int line, bool
if(!memleakfinder_global_enable) return;
if(!memleakfinder_initialised) return;
+ ASSERT(!sTrackingDataDestroyed);
if(block != 0)
{
@@ -411,6 +431,7 @@ void remove_object_block(void *block)
if(!memleakfinder_global_enable) return;
if(!memleakfinder_initialised) return;
+ if(sTrackingDataDestroyed) return;
std::map<void *, ObjectInfo>::iterator i(sObjectBlocks.find(block));
if(i != sObjectBlocks.end())