llvm.org GIT mirror llvm / e7d3af5
Fix for PR2881: fix a small leak exposed by valgrind, using a ManagedStatic. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57984 91177308-0d34-0410-b5e6-96231b3b80d8 Julien Lerouge 12 years ago
1 changed file(s) with 5 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
1111 //===----------------------------------------------------------------------===//
1212
1313 #define DONT_GET_PLUGIN_LOADER_OPTION
14 #include "llvm/Support/ManagedStatic.h"
1415 #include "llvm/Support/PluginLoader.h"
1516 #include "llvm/Support/Streams.h"
1617 #include "llvm/System/DynamicLibrary.h"
1819 #include
1920 using namespace llvm;
2021
21 static std::vector *Plugins;
22 static ManagedStatic > Plugins;
2223
2324 void PluginLoader::operator=(const std::string &Filename) {
24 if (!Plugins)
25 Plugins = new std::vector();
26
2725 std::string Error;
2826 if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
2927 cerr << "Error opening '" << Filename << "': " << Error
3432 }
3533
3634 unsigned PluginLoader::getNumPlugins() {
37 return Plugins ? Plugins->size() : 0;
35 return Plugins.isConstructed() ? Plugins->size() : 0;
3836 }
3937
4038 std::string &PluginLoader::getPlugin(unsigned num) {
41 assert(Plugins && num < Plugins->size() && "Asking for an out of bounds plugin");
39 assert(Plugins.isConstructed() && num < Plugins->size() &&
40 "Asking for an out of bounds plugin");
4241 return (*Plugins)[num];
4342 }