[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ns] ns segfault



The simple code below causes a segfault after creating a few hundred
nodes.  The bug is that the linked list of nodes does not remove nodes
when deleted, and thus stores in released heap space when a new node is
added.  Fix below: (BTW..this was a BEAR to find...)

In node.cc, after Node constructor:

Node::~Node()
{ 
	LIST_REMOVE(this, entry);
}

In node.h, after constructor decl.:

	~Node();


Code to cause the crash:

# see how many nodes can be created without running out of memory
# then test "delete" to see if memory really returned

set ns [new Simulator]

for { set i 0 } { 1 } { incr i } {
    set n [$ns node]
    if [expr (($i % 100) == 0) && ($i != 0)] {
        puts "Created $i nodes"
    }
    delete $n
}


					
			-George F. Riley ([email protected])