From d18e668fbcf40951c19a908f91b74cd41ea9f21c Mon Sep 17 00:00:00 2001 From: Torok Edwin Date: Mon, 31 Aug 2009 16:14:59 +0000 Subject: Free the constants that have no uses in ~LLVMContext. This fixes leaks from LLVMContext in multithreaded apps. Since constants are only deleted if they have no uses, it is safe to not delete a Module on shutdown, as many single-threaded tools do. Multithreaded apps should however delete the Module before destroying the Context to ensure that there are no leaks (assuming they use a different context for each thread). llvm-svn: 80590 --- llvm/lib/VMCore/ConstantsContext.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'llvm/lib/VMCore/ConstantsContext.h') diff --git a/llvm/lib/VMCore/ConstantsContext.h b/llvm/lib/VMCore/ConstantsContext.h index 22aba7e1d35..f4a2cde5d0f 100644 --- a/llvm/lib/VMCore/ConstantsContext.h +++ b/llvm/lib/VMCore/ConstantsContext.h @@ -575,6 +575,14 @@ public: // to enforce proper synchronization. typename MapTy::iterator map_begin() { return Map.begin(); } typename MapTy::iterator map_end() { return Map.end(); } + + void freeConstants() { + for (typename MapTy::iterator I=Map.begin(), E=Map.end(); + I != E; ++I) { + if (I->second->use_empty()) + delete I->second; + } + } /// InsertOrGetItem - Return an iterator for the specified element. /// If the element exists in the map, the returned iterator points to the -- cgit v1.2.3