Problem with boost:smart_ptr - invalid pointer?
I'm using boost::smart_ptr and creating instances of a smart pointer in a tight loop. I create the object, use it and then delete it.
I print out the pointer using std::cout and for the first 62 iterations, the value is always the same.
On the 63rd iteration, the pointer value I see printed out is different.
At this point my program crashes as the pointer dereferenced by the smart pointer is invalid.
Is there some memory resource I'm exhausting here? It's coincidental it's always the same iteration that fails.
I'm using Fedora Core 2 on GCC 3.3.3, but I've tested it with the same problem on PCLinuxOS, using GCC 4.
I'd post some more code, but it's quite complex due to the class structure, so I'll try to pick and post bits out later if I have time.
Thanks
Maybe tight wasn't the right word!
This is what's "in" the loop, but mConnection->Send(pack) invokes a whole bunch of code.....
So it's no help just posting this.
HBMessagePacketPtr pack = hbMessagePacketFactory::GetSingleton(). CreatePacket( hbProtocol::CMD_CHAT_SEND_MESSAGE, hbMessagePacket::HB_RELIABLE & hbMessagePacket::HB_ORDERED); mConnection->Send(pack); if (pack) delete pack;
This is what's "in" the loop, but mConnection->Send(pack) invokes a whole bunch of code.....
So it's no help just posting this.
First of all, you don't need "if (pack) delete pack". In C++ it's okay to delete a null pointer. What happens if you comment out the mConnection->Send(pack); line? Does it still crash the same way?
No - I removed the ping code so nothing is sent and it runs fine. That narrows it down a bit.
Something must be trashing the stack -> now after a full rebuild, when I call:
mConnection->Send(pack);
The debugger actually goes into a completely object & function!
mConnection->Send(pack);
The debugger actually goes into a completely object & function!
Try stepping through the code line by line and watching the EBP and ESP registers in your debugger's register window. Whenever the values in those registers get too small, you are about to corrupt the stack.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement