From b07e86315623558d1cd7c45863e5cb029cbd6abb Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 10 May 2019 14:12:26 -0400
Subject: [PATCH 31/46] FIXME: fix memory leaks; add timing info

---
 gcc/analyzer/impl-4.cc    | 37 ++++++++++++++++++++++++++++++++++---
 gcc/analyzer/supergraph.h |  6 ++++--
 2 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/gcc/analyzer/impl-4.cc b/gcc/analyzer/impl-4.cc
index a7fd4b0..41b5cbb 100644
--- a/gcc/analyzer/impl-4.cc
+++ b/gcc/analyzer/impl-4.cc
@@ -688,7 +688,7 @@ public:
   //private:
   path_state m_path_state;
 
-  auto_vec<sm_state_map *> m_checker_states;
+  auto_delete_vec<sm_state_map> m_checker_states;
 };
 
 /* A <program_point, program_state> pair, used internally by
@@ -875,6 +875,7 @@ public:
 		  const extrinsic_state &ext_state,
 		  const state_purge_map *purge_map,
 		  int verbosity);
+  ~exploded_graph ();
 
   const supergraph &get_supergraph () const { return m_sg; }
   const extrinsic_state &get_ext_state () const { return m_ext_state; }
@@ -1492,6 +1493,7 @@ public:
 			   enode->get_stack_depth (),
 			   msg);
     add_event (end_of_path);
+    free (msg);
   }
 
   void prepare_for_emission (pending_diagnostic *pd)
@@ -1705,6 +1707,10 @@ public:
     show_line_numbers_p = true;
     show_caret = true;
   }
+  ~debug_diagnostic_context ()
+  {
+    diagnostic_finish (this);
+  }
 };
 
 /* FIXME.  */
@@ -3181,6 +3187,16 @@ exploded_graph::exploded_graph (const supergraph &sg, logger *logger,
 				 program_state (ext_state));
 }
 
+/* exploded_graph's dtor.  */
+
+exploded_graph::~exploded_graph ()
+{
+  for (function_stat_map_t::iterator iter = m_per_function_stats.begin ();
+       iter != m_per_function_stats.end ();
+       ++iter)
+    delete (*iter).second;
+}
+
 /* Ensure that there is an exploded_node representing an external call to
    FUN, adding it to the worklist if creating it.
 
@@ -3275,6 +3291,8 @@ exploded_graph::add_edge (exploded_node *src, exploded_node *dest,
 void
 exploded_graph::process_worklist ()
 {
+  auto_client_timevar tv ("exploded_graph::process_worklist");
+
   while (m_worklist.length () > 0)
     {
       exploded_node *node = m_worklist.pop ();
@@ -3916,6 +3934,8 @@ shortest_paths::shortest_paths (const exploded_graph &eg)
   m_dist (eg.m_nodes.length ()),
   m_prev (eg.m_nodes.length ())
 {
+  auto_client_timevar tv ("shortest_paths");
+
   auto_vec<int> queue (eg.m_nodes.length ());
 
   for (unsigned i = 0; i < eg.m_nodes.length (); i++)
@@ -4200,7 +4220,13 @@ public:
   function_call_string_cluster (function *fun, call_string cs)
   : m_fun (fun), m_cs (cs) {}
 
-  // TODO: dtor
+  ~function_call_string_cluster ()
+  {
+    for (map_t::iterator iter = m_map.begin ();
+	 iter != m_map.end ();
+	 ++iter)
+      delete (*iter).second;
+  }
 
   void dump_dot (graphviz_out *gv) const FINAL OVERRIDE
   {
@@ -4316,7 +4342,10 @@ class root_cluster : public en_cluster
 public:
   ~root_cluster ()
   {
-    // TODO: delete the function_cluster instances in the map
+    for (map_t::iterator iter = m_map.begin ();
+	 iter != m_map.end ();
+	 ++iter)
+      delete (*iter).second;
   }
 
   void dump_dot (graphviz_out *gv) const FINAL OVERRIDE
@@ -4378,6 +4407,8 @@ state_purge_map::state_purge_map (const supergraph &sg,
 {
   JIT_LOG_FUNC (logger);
 
+  auto_client_timevar tv ("state_purge_map ctor");
+
   cgraph_node *node;
   FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node)
   {
diff --git a/gcc/analyzer/supergraph.h b/gcc/analyzer/supergraph.h
index f362d69..4c4e3b6 100644
--- a/gcc/analyzer/supergraph.h
+++ b/gcc/analyzer/supergraph.h
@@ -153,8 +153,8 @@ private:
 
   /* Data.  */
 
-  auto_vec<supernode *> m_nodes;
-  auto_vec<superedge *> m_edges;
+  auto_delete_vec<supernode> m_nodes;
+  auto_delete_vec<superedge> m_edges;
 
   typedef hash_map<basic_block, supernode *> bb_to_node_t;
   bb_to_node_t m_bb_to_initial_node;
@@ -258,6 +258,8 @@ class supernode
 class superedge
 {
  public:
+  virtual ~superedge () {}
+
   void dump_dot (graphviz_out *gv, enum supergraph_dot_flags flags) const;
 
   virtual void dump_label_to_pp (pretty_printer *pp) const = 0;
-- 
1.8.5.3

