unordered_map of maps插入崩溃

时间:2015-06-04 03:46:57

标签: c++

    ntdll.dll!RtlReportCriticalFailure()   Unknown
    ntdll.dll!RtlpReportHeapFailure()  Unknown
    ntdll.dll!RtlpHeapHandleError()    Unknown
    ntdll.dll!RtlpLogHeapFailure() Unknown
    ntdll.dll!RtlpAllocateHeap()   Unknown
    ntdll.dll!RtlAllocateHeap()    Unknown
    ntdll.dll!RtlDebugAllocateHeap()   Unknown
    ntdll.dll!string "Enabling heap debug options\n"() Unknown
    ntdll.dll!RtlAllocateHeap()    Unknown
>   msvcr120d.dll!_heap_alloc_base()   Unknown
    msvcr120d.dll!_free_dbg_nolock()   Unknown
    msvcr120d.dll!_nh_malloc_dbg() Unknown
    msvcr120d.dll!_nh_malloc_dbg() Unknown
    msvcr120d.dll!malloc() Unknown
    msvcr120d.dll!operator new(unsigned __int64)    Unknown
    apitester.exe!snap::external_api::price_reference_impl::on_item_changed(const unsigned int mkt_id, const unsigned int prod_id, const short field_id, const __int64 value) Line 94   C++
    apitester.exe!snap::external_api::price_reference_impl::initialize(std::vector<snap::price::field_id_def_t,std::allocator<snap::price::field_id_def_t> > & field_defs) Line 62  C++
    apitester.exe!snap::external_api::connection::download_price::__l5::<lambda>() Line 78  C++
    apitester.exe!boost::_bi::list0::operator()<void <lambda>(void),boost::_bi::list3<boost::system::error_code const & __ptr64,unsigned int const & __ptr64,snap::price::SNPriceBook & __ptr64> >(boost::_bi::type<void> __formal, snap::external_api::connection::download_price::__l5::void <lambda>(void) & f, boost::_bi::list3<boost::system::error_code const &,unsigned int const &,snap::price::SNPriceBook &> & __formal, int __formal) Line 193  C++
    apitester.exe!boost::_bi::bind_t<void,void <lambda>(void),boost::_bi::list0>::operator()<boost::system::error_code const ,unsigned int const ,snap::price::SNPriceBook>(const boost::system::error_code & a1, const unsigned int & a2, snap::price::SNPriceBook & a3) Line 117  C++
    apitester.exe!boost::detail::function::void_function_obj_invoker3<boost::_bi::bind_t<void,void <lambda>(void),boost::_bi::list0>,void,boost::system::error_code const & __ptr64,unsigned int const & __ptr64,snap::price::SNPriceBook & __ptr64>::invoke(boost::detail::function::function_buffer & function_obj_ptr, const boost::system::error_code & a0, const unsigned int & a1, snap::price::SNPriceBook & a2) Line 154    C++

当我的静态库发生崩溃时,我得到了上面的调用堆栈。相关代码如下。

auto mkt_map_it = _depths.find(mkt_id);
if (mkt_map_it == _depths.end())
{
    _depths.insert(std::make_pair(mkt_id, std::unordered_map<uint32_t, depth*>()));
    mkt_map_it = _depths.find(mkt_id);
}

//WTF is going on?

auto & map = mkt_map_it->second;
auto prod_it = map.find(prod_id);
if (prod_it == map.end())
{
    //The crash happens on the following line. 
    //The number of items in the map are variable when it happens (1,2,10, etc)
    map.insert(std::make_pair(prod_id, new depth()));
    prod_it = map.find(prod_id);
}

此代码位于一个函数内,该函数使用market_idprod_id的不同值反复调用。地图签名如下

std::unordered_map < uint32_t, std::unordered_map<uint32_t, depth* > > _depths;  

发生了什么,我该如何解决这个问题?

0 个答案:

没有答案