Make sure that we really attempt to destroy everything upon process exit. Gets rid of spurious leak reports in valgrind.
--- a/src/simulator/simulator.cc Wed Apr 09 10:03:28 2008 -0700
+++ b/src/simulator/simulator.cc Wed Apr 09 10:04:16 2008 -0700
@@ -57,6 +57,8 @@
SimulatorPrivate ();
~SimulatorPrivate ();
+ void Destroy ();
+
void EnableLogTo (char const *filename);
bool IsFinished (void) const;
@@ -132,6 +134,15 @@
SimulatorPrivate::~SimulatorPrivate ()
{
+ while (!m_events->IsEmpty ())
+ {
+ EventId next = m_events->RemoveNext ();
+ }
+ m_events = 0;
+}
+void
+SimulatorPrivate::Destroy ()
+{
while (!m_destroyEvents.empty ())
{
Ptr<EventImpl> ev = m_destroyEvents.front ().PeekEventImpl ();
@@ -142,11 +153,6 @@
ev->Invoke ();
}
}
- while (!m_events->IsEmpty ())
- {
- EventId next = m_events->RemoveNext ();
- }
- m_events = 0;
}
void
@@ -394,7 +400,7 @@
namespace ns3 {
-SimulatorPrivate *Simulator::m_priv = 0;
+Ptr<SimulatorPrivate> Simulator::m_priv = 0;
void Simulator::SetScheduler (Ptr<Scheduler> scheduler)
{
@@ -406,12 +412,12 @@
}
-SimulatorPrivate *
+Ptr<SimulatorPrivate>
Simulator::GetPriv (void)
{
if (m_priv == 0)
{
- m_priv = new SimulatorPrivate ();
+ m_priv = CreateObject<SimulatorPrivate> ();
Ptr<Scheduler> scheduler = CreateObject<SchedulerMap> ();
m_priv->SetScheduler (scheduler);
}
@@ -422,7 +428,11 @@
void
Simulator::Destroy (void)
{
- delete m_priv;
+ if (m_priv == 0)
+ {
+ return;
+ }
+ m_priv->Destroy ();
m_priv = 0;
}
--- a/src/simulator/simulator.h Wed Apr 09 10:03:28 2008 -0700
+++ b/src/simulator/simulator.h Wed Apr 09 10:04:16 2008 -0700
@@ -586,11 +586,11 @@
typename T1, typename T2, typename T3, typename T4, typename T5>
static Ptr<EventImpl> MakeEvent (void (*f) (U1,U2,U3,U4,U5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5);
- static SimulatorPrivate *GetPriv (void);
+ static Ptr<SimulatorPrivate> GetPriv (void);
static EventId Schedule (Time const &time, const Ptr<EventImpl> &event);
static EventId ScheduleDestroy (const Ptr<EventImpl> &event);
static EventId ScheduleNow (const Ptr<EventImpl> &event);
- static SimulatorPrivate *m_priv;
+ static Ptr<SimulatorPrivate> m_priv;
};
/**