[llvm-commits] [llvm] r57984 - /llvm/trunk/lib/Support/PluginLoader.cpp

Julien Lerouge jlerouge at apple.com
Wed Oct 22 09:30:41 PDT 2008


Author: jlerouge
Date: Wed Oct 22 11:30:41 2008
New Revision: 57984

URL: http://llvm.org/viewvc/llvm-project?rev=57984&view=rev
Log:
Fix for PR2881: fix a small leak exposed by valgrind, using a ManagedStatic.

Modified:
    llvm/trunk/lib/Support/PluginLoader.cpp

Modified: llvm/trunk/lib/Support/PluginLoader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/PluginLoader.cpp?rev=57984&r1=57983&r2=57984&view=diff

==============================================================================
--- llvm/trunk/lib/Support/PluginLoader.cpp (original)
+++ llvm/trunk/lib/Support/PluginLoader.cpp Wed Oct 22 11:30:41 2008
@@ -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 @@
 }
 
 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];
 }





More information about the llvm-commits mailing list