Problem with boost:smart_ptr - invalid pointer?

Started by
16 comments, last by DrEvil 17 years, 6 months ago
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
---------------------http://www.stodge.net
Advertisement
Please post the tight loop snippet.
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)
Maybe tight wasn't the right word!

		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.
---------------------http://www.stodge.net
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?
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)
No - I removed the ping code so nothing is sent and it runs fine. That narrows it down a bit.
---------------------http://www.stodge.net
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!
---------------------http://www.stodge.net
Do you have any recursive functions and do you ever pass large objects by value?
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)
No and I don't think so.
---------------------http://www.stodge.net
I'd post the project (Linux only) but I don't have anywhere to host the files.
---------------------http://www.stodge.net
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.
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)

This topic is closed to new replies.

Advertisement