[Warped-devel] Re: Warped errors

William Voorsluys williamvoor at gmail.com
Tue Dec 14 11:51:56 EST 2004


On Mon, 13 Dec 2004 17:29:45 -0500, Dale E. Martin
<dmartin at cliftonlabs.com> wrote:
> > This one was tough... But I kind of figured out what was going on.
> > Actually, it was tough to figure out where the problem was, as the
> > solution is pretty simple.
> 
> Wow, thanks for tracking that one down - those kinds of bugs are hard to
> find.  If you're not already aware of "valgrind" use google to find it and
> try it out.  It might have helped in this case.

I wasn't aware about this "valgrind" tool. I tracked the bug using gdb
and many couts throughout the code (I think I should start using some
advanced technology to debug my programs :-).
 
> If I understand your analysis correctly, the object is deleted and then the
> dangling pointer is pushed onto the stack.  The memory pointed to by the
> dangling pointer will then get reused.  Next time the dangling pointer gets
> accessed, the vtable pointer for the Event class is assumed but it's been
> overwritten so you get one of those two crashes.

Yes, sort of... The object is deleted, as the operator delete is
called, but its memory is not deallocated, as the operator is
overloaded. But, first, look into this code:

void
PHOLDObject::reclaimEvent(const Event *event)
{
	cout << "(Before) Sendtime: " << event->getSendTime() << endl; 
	delete event;
	cout << "(After) Sendtime: " << event->getSendTime() << endl;
}

And this is how the operator delete implementation looks like:

void
PHOLDEvent::operator delete( void *toDelete ){
  AllocatorStack<sizeof(PHOLDEvent)>::push( toDelete );
}

As long as I understood by looking at the AllocatorStack's source
code, it is nothing but a stack, right?

Now look at the output of this code:

(Before) Sendtime: 5
(After) Sendtime:
pure virtual method called.   // the program aborts.
 
If I make the method Event::getSendTime() non pure virtual like this:

     virtual const VTime &getSendTime() const { cout << "You shouldn't
be seeing this message !!! " << endl; }

The output of the previous code looks like this:

(Before) Sendtime: 5
(After) Sendtime: You shouldn't be seeing this message !!!

So it's proved that the method of the abstract base class is being
called. But that doesn't bring any error to the Warped execution as I
changed the code of garbage collecting. I was just wondering how this
is possible. Maybe there's something related with the AllocatorStack.

That's all for now!

William.




More information about the warped-devel mailing list