I have the following code that randomly crashes my application,
for(map<_type, boost::shared_ptr<CRowHeaderEx<_type> > >::iterator itr = m_RowMap.begin(); itr != m_RowMap.end(); ++itr)
{
boost::shared_ptr<CRowHeaderEx<_type> > pRow = itr->second;
time_t previoustime = pRow->get_DataReceived();
if(currenttime - previoustime > Threshold)
{
listofdeletedkey.push_back(itr->first);
}
}
The crash happens at end on the for loop in shared_ptr destructor. And this crash is random and not easily reproducible.
Exception : Unhandled exception at 0x00000752 in memory.hdmp: 0xC0000005: Access violation reading location 0x00000752.
Stack trace:
xxx.exe!boost::detail::sp_counted_base::release() Line 103 C++
xxx.exe!boost::detail::shared_count::~shared_count() Line 309 C++
xxx.exe!boost::shared_ptr<CRowHeaderEx<int> >::~shared_ptr<CRowHeaderEx<int> >() C++
xxx.exe!CRowManagerEx<int>::PurgeRecords(int Threshold) Line 385 C++
And it crashes when the dispose() function is getting called in boost::detail::sp_counted_base::release().
void release() // nothrow
{
if( BOOST_INTERLOCKED_DECREMENT( &use_count_ ) == 0 )
{
dispose();
weak_release();
}
}
disassembly:
{
dispose();
00412B57 mov edx,dword ptr [this]
00412B5A mov eax,dword ptr [edx]
00412B5C mov ecx,dword ptr [this]
00412B5F mov edx,dword ptr [eax+4]
00412B62 call edx
edx value is here 0x00000752. that is causing the access violation.