Call destroy from ~BasicCallGraph.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 25 Oct 2013 15:01:34 +0000 (15:01 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 25 Oct 2013 15:01:34 +0000 (15:01 +0000)
This fix a memory leak found by valgrind.

Calling it from the base class destructor would not destroy the BasicCallGraph
bits.

FIXME: BasicCallGraph is the only thing that inherits from CallGraph. Can
we merge the two?

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193412 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/CallGraph.h
lib/Analysis/IPA/CallGraph.cpp

index 591484dd278247db9400d4c833e3d977303aa9e1..926da76b5f3ce67178ba0317f2c1e4a403060225 100644 (file)
@@ -152,7 +152,7 @@ protected:
   CallGraph() {}
 
 public:
-  virtual ~CallGraph() { destroy(); }
+  virtual ~CallGraph() { }
 
   /// initialize - Call this method before calling other methods,
   /// re/initializes the state of the CallGraph.
index 7620fd9842ccebaac9ab1d1f09e1cfe579f5d789..6c18d0d1a6442d6bee39534d4a4998d79f798eda 100644 (file)
@@ -46,12 +46,16 @@ public:
     ExternalCallingNode(0), CallsExternalNode(0) {
       initializeBasicCallGraphPass(*PassRegistry::getPassRegistry());
     }
+  ~BasicCallGraph() {
+    destroy();
+  }
 
   // runOnModule - Compute the call graph for the specified module.
   virtual bool runOnModule(Module &M) {
     CallGraph::initialize(M);
     
     ExternalCallingNode = getOrInsertFunction(0);
+    assert(!CallsExternalNode);
     CallsExternalNode = new CallGraphNode(0);
     Root = 0;