add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
authorCraig Dowell <craigdo@ee.washington.edu>
Tue, 20 Jan 2009 22:42:11 -0800
changeset 4145 bb930262e55c
parent 4144 c59fdf82869b
child 4146 805af0f9ddd9
add NamesPriv cleanup for code that doesn't use simulator -- for valgrind-clean runs
src/core/config.cc
src/core/object-names.cc
src/core/object-names.h
--- a/src/core/config.cc	Tue Jan 20 21:55:04 2009 -0800
+++ b/src/core/config.cc	Tue Jan 20 22:42:11 2009 -0800
@@ -931,7 +931,12 @@
   d1->SetAttribute ("Source", IntegerValue (-4));
   NS_TEST_ASSERT_EQUAL (m_traceNotification, 0);
 
-
+  //
+  // The Config system is intertwined with the Names system.  In the process
+  // of parsing the paths above, we also created a NamesPriv singleton.  In
+  // order to get a valgrind-clean run we need to clean up that singleton.
+  //
+  Names::Delete ();
 
   return result;
 }
--- a/src/core/object-names.cc	Tue Jan 20 21:55:04 2009 -0800
+++ b/src/core/object-names.cc	Tue Jan 20 22:42:11 2009 -0800
@@ -17,12 +17,12 @@
  */
 
 #include <map>
-#include "ns3/object.h"
-#include "ns3/log.h"
-#include "ns3/assert.h"
-#include "ns3/abort.h"
+#include "object.h"
+#include "log.h"
+#include "assert.h"
+#include "abort.h"
+#include "object-names.h"
 #include "ns3/simulator.h"
-#include "object-names.h"
 
 namespace ns3 {
 
@@ -92,10 +92,9 @@
   Ptr<Object> FindObjectFromShortName (Ptr<Object> context, std::string name);
 
   static NamesPriv *Get (void);
-  
+  static void Delete (void);
 private:
   static NamesPriv **DoGet (void);
-  static void Delete (void);
 
   NameNode *IsNamed (Ptr<Object>);
   bool IsDuplicateName (NameNode *node, std::string name);
@@ -156,6 +155,10 @@
       delete i->second;
       i->second = 0;
     }
+
+  m_root.m_parent = 0;
+  m_root.m_name = "";
+  m_root.m_object = 0;
 }
 
 bool
@@ -444,6 +447,12 @@
     }
 }
 
+void
+Names::Delete (void)
+{
+  NamesPriv::Delete ();
+}
+
 bool
 Names::Add (std::string name, Ptr<Object> object)
 {
--- a/src/core/object-names.h	Tue Jan 20 21:55:04 2009 -0800
+++ b/src/core/object-names.h	Tue Jan 20 22:42:11 2009 -0800
@@ -171,8 +171,14 @@
   template <typename T>
   static Ptr<T> FindObjectFromShortName (Ptr<Object> context, std::string name);
 
+  /**
+   * Clean up all of the data structures of the implementation and delete the
+   * underlying singleton.  Used to get valgrind-clean runs if the simulator
+   * is not run.  Normally singleton cleanup is scheduled on Simulator::Destroy.
+   */
+  static void Delete (void);
+
 private:
-
   /**
    * \internal
    *