Fix memory leaks, patch contributed by Morten Ofstad!

llvm-svn: 17999
This commit is contained in:
Chris Lattner 2004-11-19 17:09:48 +00:00
parent 37bcd99622
commit a8a8a03a85
1 changed files with 21 additions and 15 deletions

View File

@ -68,9 +68,6 @@ namespace {
} }
std::cerr << '\n'; std::cerr << '\n';
// Clear out results so we don't get duplicate warnings on
// next call...
Ts.clear();
return true; return true;
} }
return false; return false;
@ -82,21 +79,26 @@ namespace {
const char* const Name; const char* const Name;
}; };
typedef LeakDetectorImpl<void> Objects; LeakDetectorImpl<void> *Objects;
typedef LeakDetectorImpl<Value> LLVMObjects; LeakDetectorImpl<Value> *LLVMObjects;
Objects& getObjects() { LeakDetectorImpl<void> &getObjects() {
static Objects *o = 0; if (Objects == 0)
if (o == 0) Objects = new LeakDetectorImpl<void>("GENERIC");
o = new Objects("GENERIC"); return *Objects;
return *o;
} }
LLVMObjects& getLLVMObjects() { LeakDetectorImpl<Value> &getLLVMObjects() {
static LLVMObjects *o = 0; if (LLVMObjects == 0)
if (o == 0) LLVMObjects = new LeakDetectorImpl<Value>("LLVM");
o = new LLVMObjects("LLVM"); return *LLVMObjects;
return *o; }
void clearGarbage() {
delete Objects;
delete LLVMObjects;
Objects = 0;
LLVMObjects = 0;
} }
} }
@ -122,4 +124,8 @@ void LeakDetector::checkForGarbageImpl(const std::string &Message) {
getLLVMObjects().hasGarbage(Message)) getLLVMObjects().hasGarbage(Message))
std::cerr << "\nThis is probably because you removed an object, but didn't " std::cerr << "\nThis is probably because you removed an object, but didn't "
"delete it. Please check your code for memory leaks.\n"; "delete it. Please check your code for memory leaks.\n";
// Clear out results so we don't get duplicate warnings on
// next call...
clearGarbage();
} }