From 6d4e5021092fc7e7d859634108ae423b505d9ea4 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 2 May 2007 10:33:39 +0200 Subject: [PATCH] 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. --- src/node/node.cc | 26 +++++++++++++++++++++++--- src/node/node.h | 4 +++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/node/node.cc b/src/node/node.cc index a85fbc714..ab9a6c669 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -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(); } diff --git a/src/node/node.h b/src/node/node.h index e2d728493..18fdec7d6 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -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