Index: lib/Support/DynamicLibrary.cpp =================================================================== --- lib/Support/DynamicLibrary.cpp +++ lib/Support/DynamicLibrary.cpp @@ -9,8 +9,6 @@ // // This file implements the operating system DynamicLibrary concept. // -// FIXME: This file leaks ExplicitSymbols and OpenedHandles! -// //===----------------------------------------------------------------------===// #include "llvm/Support/DynamicLibrary.h" @@ -51,7 +49,7 @@ //=== independent code. //===----------------------------------------------------------------------===// -static DenseSet *OpenedHandles = nullptr; +static llvm::ManagedStatic > OpenedHandles; DynamicLibrary DynamicLibrary::getPermanentLibrary(const char *filename, std::string *errMsg) { @@ -70,9 +68,6 @@ handle = RTLD_DEFAULT; #endif - if (!OpenedHandles) - OpenedHandles = new DenseSet(); - // If we've already loaded this library, dlclose() the handle in order to // keep the internal refcount at +1. if (!OpenedHandles->insert(handle).second) @@ -121,7 +116,7 @@ #if HAVE_DLFCN_H // Now search the libraries. - if (OpenedHandles) { + if (OpenedHandles.isConstructed()) { for (DenseSet::iterator I = OpenedHandles->begin(), E = OpenedHandles->end(); I != E; ++I) { //lt_ptr ptr = lt_dlsym(*I, symbolName); Index: lib/Support/Windows/DynamicLibrary.inc =================================================================== --- lib/Support/Windows/DynamicLibrary.inc +++ lib/Support/Windows/DynamicLibrary.inc @@ -39,7 +39,7 @@ //=== and must not be UNIX code. //===----------------------------------------------------------------------===// -static DenseSet *OpenedHandles; +static llvm::ManagedStatic > OpenedHandles; static BOOL CALLBACK ELM_Callback(WIN32_ELMCB_PCSTR ModuleName, ULONG_PTR ModuleBase, @@ -54,8 +54,6 @@ if (!filename) { // When no file is specified, enumerate all DLLs and EXEs in the process. - if (OpenedHandles == 0) - OpenedHandles = new DenseSet(); EnumerateLoadedModules(GetCurrentProcess(), ELM_Callback, 0); // Dummy library that represents "search all handles". @@ -77,9 +75,6 @@ return DynamicLibrary(); } - if (OpenedHandles == 0) - OpenedHandles = new DenseSet(); - // If we've already loaded this library, FreeLibrary() the handle in order to // keep the internal refcount at +1. if (!OpenedHandles->insert(a_handle).second) @@ -125,7 +120,7 @@ } // Now search the libraries. - if (OpenedHandles) { + if (OpenedHandles.isConstructed()) { for (DenseSet::iterator I = OpenedHandles->begin(), E = OpenedHandles->end(); I != E; ++I) { FARPROC ptr = GetProcAddress((HMODULE)*I, symbolName);