vagetablechicken opened a new issue #2697: Using a range for loop and erasing an item may cause mem error URL: https://github.com/apache/incubator-doris/issues/2697 **Describe the bug** https://github.com/apache/incubator-doris/blob/367b4c058c2c2c5da921f7227b83f0abb95a9198/be/src/olap/txn_manager.cpp#L419-L440 **To Reproduce** Steps to reproduce the behavior: 1. Create a simple test ``` #include <map> #include <iostream> int main(){ std::map<int,std::map<int,int> > m; m[0][2]=0; m[1][3]=1; for(auto& it: m){ auto ita=it.second.find(2); if(ita != it.second.end()) it.second.erase(2); if(it.second.empty()){ m.erase(it.first); } } return 0; } ``` 2. g++ -ggdb -std=c++11 main.cpp && valgrind ./a.out output: ``` $ valgrind ./a.out ==4856== Memcheck, a memory error detector ==4856== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==4856== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info ==4856== Command: ./a.out ==4856== ==4856== Invalid read of size 8 ==4856== at 0x4EDFA60: std::_Rb_tree_increment(std::_Rb_tree_node_base const*) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21) ==4856== by 0x40127C: std::_Rb_tree_iterator<std::pair<int const, std::map<int, int, std::less<int>, std::allocator<std::pair<int const, int> > > > >::operator++() (stl_tree.h:205) ==4856== by 0x400DF7: main (main.cpp:8) ==4856== Address 0x5ab7c98 is 24 bytes inside a block of size 88 free'd ==4856== at 0x4C2F400: operator delete(void*) (vg_replace_malloc.c:576) ``` **Additional context** We met a core in production env ``` Aborted at 1578365820 (unix time) try "date -d @1578365820" if you are using GNU date *** PC: @ 0x2d086c4 std::_Rb_tree_increment() SIGSEGV (@0x18) received by PID 337483 (TID 0x7f5f94512700) from PID 24; stack trace: *** @ 0x7f600c05b250 (unknown) @ 0x2d086c4 std::_Rb_tree_increment() @ 0xe7929f doris::TxnManager::force_rollback_tablet_related_txns() @ 0x1391698 doris::TaskWorkerPool::_drop_tablet_worker_thread_callback() @ 0x7f600be11dc5 start_thread @ 0x7f600c11d73d __clone ``` Maybe this mem error is the reason.
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org