diff options
author | Chris Lattner <sabre@nondot.org> | 2004-11-19 17:09:48 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-11-19 17:09:48 +0000 |
commit | 9945826d50e46212234a6297fda88e2de50f48a6 (patch) | |
tree | 2aa6f2697e04c7df47c41bcf2339f35aaab077fc | |
parent | c540ebbc1b7c2f6a92a968b4d36137a7332cea32 (diff) |
Fix memory leaks, patch contributed by Morten Ofstad!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17999 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/VMCore/LeakDetector.cpp | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/lib/VMCore/LeakDetector.cpp b/lib/VMCore/LeakDetector.cpp index 807bd22b07..c8e7f4c6a5 100644 --- a/lib/VMCore/LeakDetector.cpp +++ b/lib/VMCore/LeakDetector.cpp @@ -68,9 +68,6 @@ namespace { } 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 @@ namespace { 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 @@ void LeakDetector::checkForGarbageImpl(const std::string &Message) { 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(); } |