Skip to content

Commit 59e5a64

Browse files
committedFeb 21, 2017
Do not leak OpenedHandles.
Reviewed by Vedant Kumar (D30178) llvm-svn: 295737
1 parent 5afda30 commit 59e5a64

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed
 

‎llvm/lib/Support/DynamicLibrary.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
//
1010
// This file implements the operating system DynamicLibrary concept.
1111
//
12-
// FIXME: This file leaks ExplicitSymbols and OpenedHandles!
13-
//
1412
//===----------------------------------------------------------------------===//
1513

1614
#include "llvm/Support/DynamicLibrary.h"
@@ -51,7 +49,7 @@ using namespace llvm::sys;
5149
//=== independent code.
5250
//===----------------------------------------------------------------------===//
5351

54-
static DenseSet<void *> *OpenedHandles = nullptr;
52+
static llvm::ManagedStatic<DenseSet<void *> > OpenedHandles;
5553

5654
DynamicLibrary DynamicLibrary::getPermanentLibrary(const char *filename,
5755
std::string *errMsg) {
@@ -70,9 +68,6 @@ DynamicLibrary DynamicLibrary::getPermanentLibrary(const char *filename,
7068
handle = RTLD_DEFAULT;
7169
#endif
7270

73-
if (!OpenedHandles)
74-
OpenedHandles = new DenseSet<void *>();
75-
7671
// If we've already loaded this library, dlclose() the handle in order to
7772
// keep the internal refcount at +1.
7873
if (!OpenedHandles->insert(handle).second)
@@ -121,7 +116,7 @@ void* DynamicLibrary::SearchForAddressOfSymbol(const char *symbolName) {
121116

122117
#if defined(HAVE_DLFCN_H) && defined(HAVE_DLOPEN)
123118
// Now search the libraries.
124-
if (OpenedHandles) {
119+
if (OpenedHandles.isConstructed()) {
125120
for (DenseSet<void *>::iterator I = OpenedHandles->begin(),
126121
E = OpenedHandles->end(); I != E; ++I) {
127122
//lt_ptr ptr = lt_dlsym(*I, symbolName);

‎llvm/lib/Support/Windows/DynamicLibrary.inc

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
//
1010
// This file provides the Win32 specific implementation of DynamicLibrary.
1111
//
12+
// FIXME: This file leaks OpenedHandles!
13+
//
1214
//===----------------------------------------------------------------------===//
1315

1416
#include "WindowsSupport.h"

0 commit comments

Comments
 (0)