destroy the Node vector upon Simulator::Destroy rather than wait until the global static destructor of Node::g_nodes is invoked. This fixes a bad assert caught with valgrind.

Mathieu Lacage 2007-05-02 10:33:39 +02:00
parent 1eeab81136
commit 6d4e502109
2 changed files with 26 additions and 4 deletions

View File

@ -25,11 +25,11 @@
#include "node.h"
#include "node-list.h"
#include "net-device.h"
#include "ns3/simulator.h"
namespace ns3{
Node::SmartNodeVec_t Node::g_prototypes; // The node prototypes stack
Node::SmartNodeVec_t Node::g_nodes; // All nodes
Node::Node()
: m_id(0), m_sid(0)
@ -101,11 +101,31 @@ void Node::Dispose()
m_devices.erase (m_devices.begin (), m_devices.end ());
}
Node::SmartNodeVec_t **
Node::GetNodeVector (void)
{
static SmartNodeVec_t *vector = 0;
if (vector == 0)
{
vector = new SmartNodeVec_t ();
Simulator::ScheduleDestroy (&Node::DestroyNodes);
}
return &vector;
}
void
Node::DestroyNodes (void)
{
SmartNodeVec_t **vector = GetNodeVector ();
delete *vector;
*vector = 0;
}
// Node stack creation and management routines.
Node* Node::Create()
{
Node* n = g_prototypes.Back()->Copy(); // Copy the top of the stack
g_nodes.Add(n); // Add to smart vector (mem mgmt)
(*GetNodeVector ())->Add (n);
NodeList::Add (n); // Add to global list of nodes
return n;
}
@ -142,7 +162,7 @@ void Node::PopNodePrototype()
void Node::ClearAll()
{ // Delete all nodes for memory leak checking, including prototypes
g_nodes.Clear();
(*GetNodeVector ())->Clear ();
g_prototypes.Clear();
}

View File

@ -165,9 +165,11 @@ public:
// Global static variables
private:
static uint32_t g_nextId; // Next available ID
static SmartNodeVec_t g_nodes; // Vector of all nodes created
static SmartNodeVec_t g_prototypes; // Node prototype stack
static Node::SmartNodeVec_t **GetNodeVector (void);
static void DestroyNodes (void);
protected:
void SetId(uint32_t); // NodeList::Add() calls this