views:

20

answers:

1

I am using hash_map in application as

typedef hash_map<DWORD,CComPtr<IInterfaceXX>> MapDword2Interface;

In main application I am using static instance of this map

static MapDword2Interface m_mapDword2Interface;

I have got one crash dump from one of the client machines which point to the crash in clearing this map

I opened that crash dump and here is assembly during debugging

> call        std::list<std::pair<unsigned long const ,ATL::CComPtr<IInterfaceXX> >,std::allocator<std::pair<unsigned long const ,ATL::CComPtr<IInterfaceXX> > > >::clear 
> mov         eax,dword ptr [CMainApp::m_mapDword2Interface+8 (49XXXXX)] 

Here is code where crash dump is pointing. Below code is from stl:list file

void clear()
        {   // erase all

 #if _HAS_ITERATOR_DEBUGGING
        this->_Orphan_ptr(*this, 0);
 #endif /* _HAS_ITERATOR_DEBUGGING */

        _Nodeptr _Pnext;
        _Nodeptr _Pnode = _Nextnode(_Myhead);
        _Nextnode(_Myhead) = _Myhead;
        _Prevnode(_Myhead) = _Myhead;
        _Mysize = 0;

        for (; _Pnode != _Myhead; _Pnode = _Pnext)
            {   // delete an element
            _Pnext = _Nextnode(_Pnode);
            this->_Alnod.destroy(_Pnode);
            this->_Alnod.deallocate(_Pnode, 1);
            }
        }

Crash is pointing to the this->_Alnod.destroy(_Pnode); statement in above code.

I am not able to guess it, what could be reason.

Any ideas???

How can I make sure, even is there is something wrong with the map , it should not crash?

+1  A: 

It is my assumption:

OLE needs call of global-wide pairs OleInitialize / OleUninitialize - but static hash map destroyed after OLE memory management system has been destroyed. So ensure that map is cleared before OleUninitialize.

Dewfy
How can I make sure that static object is destroyed before OleUninitialize?
Alien01
@Alien01 just make your map non static. If you any way want global visible map, just create singleton class that (1) exposes the map (2) has explicit shutdown method - to allow destroying before OleUninitialize
Dewfy