Make sure that we really attempt to destroy everything upon process exit. Gets rid of spurious leak reports in valgrind.
1.1 --- a/src/simulator/simulator.cc Wed Apr 09 10:03:28 2008 -0700
1.2 +++ b/src/simulator/simulator.cc Wed Apr 09 10:04:16 2008 -0700
1.3 @@ -57,6 +57,8 @@
1.4 SimulatorPrivate ();
1.5 ~SimulatorPrivate ();
1.6
1.7 + void Destroy ();
1.8 +
1.9 void EnableLogTo (char const *filename);
1.10
1.11 bool IsFinished (void) const;
1.12 @@ -132,6 +134,15 @@
1.13
1.14 SimulatorPrivate::~SimulatorPrivate ()
1.15 {
1.16 + while (!m_events->IsEmpty ())
1.17 + {
1.18 + EventId next = m_events->RemoveNext ();
1.19 + }
1.20 + m_events = 0;
1.21 +}
1.22 +void
1.23 +SimulatorPrivate::Destroy ()
1.24 +{
1.25 while (!m_destroyEvents.empty ())
1.26 {
1.27 Ptr<EventImpl> ev = m_destroyEvents.front ().PeekEventImpl ();
1.28 @@ -142,11 +153,6 @@
1.29 ev->Invoke ();
1.30 }
1.31 }
1.32 - while (!m_events->IsEmpty ())
1.33 - {
1.34 - EventId next = m_events->RemoveNext ();
1.35 - }
1.36 - m_events = 0;
1.37 }
1.38
1.39 void
1.40 @@ -394,7 +400,7 @@
1.41
1.42 namespace ns3 {
1.43
1.44 -SimulatorPrivate *Simulator::m_priv = 0;
1.45 +Ptr<SimulatorPrivate> Simulator::m_priv = 0;
1.46
1.47 void Simulator::SetScheduler (Ptr<Scheduler> scheduler)
1.48 {
1.49 @@ -406,12 +412,12 @@
1.50 }
1.51
1.52
1.53 -SimulatorPrivate *
1.54 +Ptr<SimulatorPrivate>
1.55 Simulator::GetPriv (void)
1.56 {
1.57 if (m_priv == 0)
1.58 {
1.59 - m_priv = new SimulatorPrivate ();
1.60 + m_priv = CreateObject<SimulatorPrivate> ();
1.61 Ptr<Scheduler> scheduler = CreateObject<SchedulerMap> ();
1.62 m_priv->SetScheduler (scheduler);
1.63 }
1.64 @@ -422,7 +428,11 @@
1.65 void
1.66 Simulator::Destroy (void)
1.67 {
1.68 - delete m_priv;
1.69 + if (m_priv == 0)
1.70 + {
1.71 + return;
1.72 + }
1.73 + m_priv->Destroy ();
1.74 m_priv = 0;
1.75 }
1.76
2.1 --- a/src/simulator/simulator.h Wed Apr 09 10:03:28 2008 -0700
2.2 +++ b/src/simulator/simulator.h Wed Apr 09 10:04:16 2008 -0700
2.3 @@ -586,11 +586,11 @@
2.4 typename T1, typename T2, typename T3, typename T4, typename T5>
2.5 static Ptr<EventImpl> MakeEvent (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
2.6
2.7 - static SimulatorPrivate *GetPriv (void);
2.8 + static Ptr<SimulatorPrivate> GetPriv (void);
2.9 static EventId Schedule (Time const &time, const Ptr<EventImpl> &event);
2.10 static EventId ScheduleDestroy (const Ptr<EventImpl> &event);
2.11 static EventId ScheduleNow (const Ptr<EventImpl> &event);
2.12 - static SimulatorPrivate *m_priv;
2.13 + static Ptr<SimulatorPrivate> m_priv;
2.14 };
2.15
2.16 /**