summaryrefslogtreecommitdiff
path: root/lib/common/DebugMemLeakFinder.cpp
diff options
context:
space:
mode:
authorMartin Ebourne <martin@ebourne.me.uk>2005-11-30 23:18:04 +0000
committerMartin Ebourne <martin@ebourne.me.uk>2005-11-30 23:18:04 +0000
commit15fe4e977048085cb929a50e0561b223cf95c9a9 (patch)
treea377f06f289bb78fb608da11f43ba52cb961e4d0 /lib/common/DebugMemLeakFinder.cpp
parenta1fc249484f3c88630901828918c72897dd2c18d (diff)
Merged martin/xattr at r5 to trunk
Diffstat (limited to 'lib/common/DebugMemLeakFinder.cpp')
-rwxr-xr-xlib/common/DebugMemLeakFinder.cpp40
1 files changed, 22 insertions, 18 deletions
diff --git a/lib/common/DebugMemLeakFinder.cpp b/lib/common/DebugMemLeakFinder.cpp
index e2a4a140..6c7fd3eb 100755
--- a/lib/common/DebugMemLeakFinder.cpp
+++ b/lib/common/DebugMemLeakFinder.cpp
@@ -93,33 +93,37 @@ void *memleakfinder_realloc(void *ptr, size_t size)
// Check it's been allocated
std::map<void *, MallocBlockInfo>::iterator i(sMallocBlocks.find(ptr));
- if(i == sMallocBlocks.end())
+ if(ptr && i == sMallocBlocks.end())
{
TRACE1("Block %x realloc(), but not in list. Error? Or allocated in startup static objects?\n", ptr);
- void *b = ::realloc(ptr, size);
- memleakfinder_malloc_add_block(b, size, "FOUND-IN-REALLOC", 0);
- return b;
}
void *b = ::realloc(ptr, size);
-
- // Worked?
- if(b != 0)
+
+ if(ptr && i!=sMallocBlocks.end())
{
- // Update map
- MallocBlockInfo inf = i->second;
- inf.size = size;
- sMallocBlocks.erase(i);
- sMallocBlocks[b] = inf;
-
- if(sTrackMallocInSection)
+ // Worked?
+ if(b != 0)
{
- std::set<void *>::iterator si(sSectionMallocBlocks.find(ptr));
- if(si != sSectionMallocBlocks.end()) sSectionMallocBlocks.erase(si);
- sSectionMallocBlocks.insert(b);
+ // Update map
+ MallocBlockInfo inf = i->second;
+ inf.size = size;
+ sMallocBlocks.erase(i);
+ sMallocBlocks[b] = inf;
+
+ if(sTrackMallocInSection)
+ {
+ std::set<void *>::iterator si(sSectionMallocBlocks.find(ptr));
+ if(si != sSectionMallocBlocks.end()) sSectionMallocBlocks.erase(si);
+ sSectionMallocBlocks.insert(b);
+ }
}
}
-
+ else
+ {
+ memleakfinder_malloc_add_block(b, size, "FOUND-IN-REALLOC", 0);
+ }
+
//TRACE3("realloc(), %d, %08x->%08x\n", size, ptr, b);
return b;
}