[llvm] r296748 - Do not leak OpenedHandles.
Vassil Vassilev via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 2 06:30:05 PST 2017
Author: vvassilev
Date: Thu Mar 2 08:30:05 2017
New Revision: 296748
URL: http://llvm.org/viewvc/llvm-project?rev=296748&view=rev
Log:
Do not leak OpenedHandles.
Modified:
llvm/trunk/lib/Support/Windows/DynamicLibrary.inc
Modified: llvm/trunk/lib/Support/Windows/DynamicLibrary.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/DynamicLibrary.inc?rev=296748&r1=296747&r2=296748&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/DynamicLibrary.inc (original)
+++ llvm/trunk/lib/Support/Windows/DynamicLibrary.inc Thu Mar 2 08:30:05 2017
@@ -9,8 +9,6 @@
//
// This file provides the Win32 specific implementation of DynamicLibrary.
//
-// FIXME: This file leaks OpenedHandles!
-//
//===----------------------------------------------------------------------===//
#include "WindowsSupport.h"
@@ -35,7 +33,7 @@ using namespace sys;
typedef BOOL (WINAPI *fpEnumerateLoadedModules)(HANDLE,PENUMLOADED_MODULES_CALLBACK64,PVOID);
static fpEnumerateLoadedModules fEnumerateLoadedModules;
-static DenseSet<HMODULE> *OpenedHandles;
+static llvm::ManagedStatic<DenseSet<HMODULE> > OpenedHandles;
static bool loadDebugHelp(void) {
HMODULE hLib = ::LoadLibraryW(L"Dbghelp.dll");
@@ -59,9 +57,6 @@ DynamicLibrary DynamicLibrary::getPerman
if (!filename) {
// When no file is specified, enumerate all DLLs and EXEs in the process.
- if (OpenedHandles == 0)
- OpenedHandles = new DenseSet<HMODULE>();
-
if (!fEnumerateLoadedModules) {
if (!loadDebugHelp()) {
assert(false && "These APIs should always be available");
@@ -89,9 +84,6 @@ DynamicLibrary DynamicLibrary::getPerman
return DynamicLibrary();
}
- if (OpenedHandles == 0)
- OpenedHandles = new DenseSet<HMODULE>();
-
// 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)
@@ -137,7 +129,7 @@ void* DynamicLibrary::SearchForAddressOf
}
// Now search the libraries.
- if (OpenedHandles) {
+ if (OpenedHandles.isConstructed()) {
for (DenseSet<HMODULE>::iterator I = OpenedHandles->begin(),
E = OpenedHandles->end(); I != E; ++I) {
FARPROC ptr = GetProcAddress((HMODULE)*I, symbolName);
More information about the llvm-commits
mailing list