[llvm-commits] CVS: llvm/lib/VMCore/LeakDetector.cpp
Chris Lattner
lattner at cs.uiuc.edu
Fri Nov 19 09:10:00 PST 2004
Changes in directory llvm/lib/VMCore:
LeakDetector.cpp updated: 1.11 -> 1.12
---
Log message:
Fix memory leaks, patch contributed by Morten Ofstad!
---
Diffs of the changes: (+21 -15)
Index: llvm/lib/VMCore/LeakDetector.cpp
diff -u llvm/lib/VMCore/LeakDetector.cpp:1.11 llvm/lib/VMCore/LeakDetector.cpp:1.12
--- llvm/lib/VMCore/LeakDetector.cpp:1.11 Wed Sep 1 17:55:37 2004
+++ llvm/lib/VMCore/LeakDetector.cpp Fri Nov 19 11:09:48 2004
@@ -68,9 +68,6 @@
}
std::cerr << '\n';
- // Clear out results so we don't get duplicate warnings on
- // next call...
- Ts.clear();
return true;
}
return false;
@@ -82,21 +79,26 @@
const char* const Name;
};
- typedef LeakDetectorImpl<void> Objects;
- typedef LeakDetectorImpl<Value> LLVMObjects;
+ LeakDetectorImpl<void> *Objects;
+ LeakDetectorImpl<Value> *LLVMObjects;
- Objects& getObjects() {
- static Objects *o = 0;
- if (o == 0)
- o = new Objects("GENERIC");
- return *o;
+ LeakDetectorImpl<void> &getObjects() {
+ if (Objects == 0)
+ Objects = new LeakDetectorImpl<void>("GENERIC");
+ return *Objects;
}
- LLVMObjects& getLLVMObjects() {
- static LLVMObjects *o = 0;
- if (o == 0)
- o = new LLVMObjects("LLVM");
- return *o;
+ LeakDetectorImpl<Value> &getLLVMObjects() {
+ if (LLVMObjects == 0)
+ LLVMObjects = new LeakDetectorImpl<Value>("LLVM");
+ return *LLVMObjects;
+ }
+
+ void clearGarbage() {
+ delete Objects;
+ delete LLVMObjects;
+ Objects = 0;
+ LLVMObjects = 0;
}
}
@@ -122,4 +124,8 @@
getLLVMObjects().hasGarbage(Message))
std::cerr << "\nThis is probably because you removed an object, but didn't "
"delete it. Please check your code for memory leaks.\n";
+
+ // Clear out results so we don't get duplicate warnings on
+ // next call...
+ clearGarbage();
}
More information about the llvm-commits
mailing list