map/set iterator not dereferencable異常

來源:互聯網
上載者:User

今天完成一個會話架構模組後,編譯運行,某個會話生命週期結束後,就會出現這個錯誤提示:map/set iterator not dereferencable



看這個提示的意思大概是STL的迭代器不可引用,可能是越界了。仔細核查了下代碼,果不其然:


//遍曆會話表;SessionTableIter iter = m_sessionTable.begin();for (;iter != m_sessionTable.end();){//判斷指標是否為空白;if (NULL == iter->second){std::string strSessionId = iter->first;RemoveAssistMappingBySessionID(strSessionId);m_sessionTable.erase( iter++ ); continue;}//會話是否關閉;if (iter->second->isClosed()){delete iter->second;iter->second = NULL;m_sessionTable.erase( iter++ );  //這裡已經將該節點刪除;std::string strSessionId = iter->first;      RemoveAssistMappingBySessionID(strSessionId);//而這裡又企圖對該節點的值進行使用,整個業務就亂了。當該節點正好是最後一個節點的時候就會越界,報錯。}/*  以下代碼略 */


雖然是個很低級的邏輯順序錯誤,但是還是mark下吧~




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.