From 89f4df3eae4ec57b5bce51d0815c21dc2e31abca Mon Sep 17 00:00:00 2001 From: Julien Lerouge Date: Wed, 22 Oct 2008 16:30:41 +0000 Subject: [PATCH] Fix for PR2881: fix a small leak exposed by valgrind, using a ManagedStatic. llvm-svn: 57984 --- lib/Support/PluginLoader.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/Support/PluginLoader.cpp b/lib/Support/PluginLoader.cpp index 0635a9d52ca..5acf1d13ee9 100644 --- a/lib/Support/PluginLoader.cpp +++ b/lib/Support/PluginLoader.cpp @@ -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 using namespace llvm; -static std::vector *Plugins; +static ManagedStatic > Plugins; void PluginLoader::operator=(const std::string &Filename) { - if (!Plugins) - Plugins = new std::vector(); - 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]; }