Skip to content
This repository has been archived by the owner on Feb 5, 2019. It is now read-only.

Commit

Permalink
Don't leak the mutex when loading dynamic libraries.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121119 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
resistor committed Dec 7, 2010
1 parent 2804235 commit 0ea112f
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions lib/Support/DynamicLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,12 @@ using namespace llvm::sys;
//=== independent code.
//===----------------------------------------------------------------------===//

static SmartMutex<true>* HandlesMutex;
static std::vector<void *> *OpenedHandles = 0;

static bool InitializeMutex() {
HandlesMutex = new SmartMutex<true>;
return HandlesMutex != 0;
}

static bool EnsureMutexInitialized() {
static bool result = InitializeMutex();
return result;
static SmartMutex<true>& getMutex() {
static SmartMutex<true> HandlesMutex;
return HandlesMutex;
}


Expand All @@ -88,8 +83,7 @@ bool DynamicLibrary::LoadLibraryPermanently(const char *Filename,
if (Filename == NULL)
H = RTLD_DEFAULT;
#endif
EnsureMutexInitialized();
SmartScopedLock<true> Lock(*HandlesMutex);
SmartScopedLock<true> Lock(getMutex());
if (OpenedHandles == 0)
OpenedHandles = new std::vector<void *>();
OpenedHandles->push_back(H);
Expand Down Expand Up @@ -124,8 +118,7 @@ void* DynamicLibrary::SearchForAddressOfSymbol(const char* symbolName) {

#if HAVE_DLFCN_H
// Now search the libraries.
EnsureMutexInitialized();
SmartScopedLock<true> Lock(*HandlesMutex);
SmartScopedLock<true> Lock(getMutex());
if (OpenedHandles) {
for (std::vector<void *>::iterator I = OpenedHandles->begin(),
E = OpenedHandles->end(); I != E; ++I) {
Expand Down

0 comments on commit 0ea112f

Please sign in to comment.