[Box Backup-commit] COMMIT r1341 - box/chris/general/lib/common

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Sat Mar 3 23:57:23 GMT 2007


Author: chris
Date: 2007-03-03 23:57:23 +0000 (Sat, 03 Mar 2007)
New Revision: 1341

Modified:
   box/chris/general/lib/common/DebugMemLeakFinder.cpp
Log:
Watch out for our leak tracking data being destroyed and don't crash when
subsequent objects are destroyed.


Modified: box/chris/general/lib/common/DebugMemLeakFinder.cpp
===================================================================
--- box/chris/general/lib/common/DebugMemLeakFinder.cpp	2007-03-03 23:56:12 UTC (rev 1340)
+++ box/chris/general/lib/common/DebugMemLeakFinder.cpp	2007-03-03 23:57:23 UTC (rev 1341)
@@ -49,6 +49,17 @@
 {
 	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 @@
 {
 	InternalAllocGuard guard;
 
+	ASSERT(!sTrackingDataDestroyed);
+
 	memleakfinder_notaleak_insert_pre();
 	if(memleakfinder_global_enable && memleakfinder_initialised)
 	{
@@ -258,6 +271,8 @@
 	InternalAllocGuard guard;
 
 	ASSERT(memleakfinder_initialised);
+	ASSERT(!sTrackingDataDestroyed);
+
 	sTrackMallocInSection = true;
 	sSectionMallocBlocks.clear();
 	sTrackObjectsInSection = true;
@@ -270,6 +285,7 @@
 	InternalAllocGuard guard;
 
 	ASSERT(memleakfinder_initialised);
+	ASSERT(!sTrackingDataDestroyed);
 
 	std::set<void *>::iterator s(sSectionMallocBlocks.begin());
 	for(; s != sSectionMallocBlocks.end(); ++s)
@@ -295,6 +311,7 @@
 	InternalAllocGuard guard;
 
 	ASSERT(memleakfinder_initialised);
+	ASSERT(!sTrackingDataDestroyed);
 
 	int n = 0;
 	
@@ -316,6 +333,8 @@
 {
 	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 @@
 
 	if(!memleakfinder_global_enable) return;
 	if(!memleakfinder_initialised)   return;
+	ASSERT(!sTrackingDataDestroyed);
 
 	if(block != 0)
 	{
@@ -411,6 +431,7 @@
 
 	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())




More information about the Boxbackup-commit mailing list