mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-20 18:48:13 +00:00
Fix for PR2881: fix a small leak exposed by valgrind, using a ManagedStatic.
llvm-svn: 57984
This commit is contained in:
parent
16e190fb8b
commit
89f4df3eae
@ -12,6 +12,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#define DONT_GET_PLUGIN_LOADER_OPTION
|
||||
#include "llvm/Support/ManagedStatic.h"
|
||||
#include "llvm/Support/PluginLoader.h"
|
||||
#include "llvm/Support/Streams.h"
|
||||
#include "llvm/System/DynamicLibrary.h"
|
||||
@ -19,12 +20,9 @@
|
||||
#include <vector>
|
||||
using namespace llvm;
|
||||
|
||||
static std::vector<std::string> *Plugins;
|
||||
static ManagedStatic<std::vector<std::string> > Plugins;
|
||||
|
||||
void PluginLoader::operator=(const std::string &Filename) {
|
||||
if (!Plugins)
|
||||
Plugins = new std::vector<std::string>();
|
||||
|
||||
std::string Error;
|
||||
if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
|
||||
cerr << "Error opening '" << Filename << "': " << Error
|
||||
@ -35,10 +33,11 @@ void PluginLoader::operator=(const std::string &Filename) {
|
||||
}
|
||||
|
||||
unsigned PluginLoader::getNumPlugins() {
|
||||
return Plugins ? Plugins->size() : 0;
|
||||
return Plugins.isConstructed() ? Plugins->size() : 0;
|
||||
}
|
||||
|
||||
std::string &PluginLoader::getPlugin(unsigned num) {
|
||||
assert(Plugins && num < Plugins->size() && "Asking for an out of bounds plugin");
|
||||
assert(Plugins.isConstructed() && num < Plugins->size() &&
|
||||
"Asking for an out of bounds plugin");
|
||||
return (*Plugins)[num];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user