#include #include struct comparestrings { bool operator()(const std::string & left, const std::string & right) const { return left.compare(right); } }; main() { std::multimap testmap; testmap.erase("key1"); testmap.insert(std::pair("key1", "value1")); testmap.erase("key2"); // <--- segfault here } etna% valgrind ./a.out ==9214== Memcheck, a memory error detector. ==9214== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al. ==9214== Using LibVEX rev 1732, a library for dynamic binary translation. ==9214== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP. ==9214== Using valgrind-3.2.3-Debian, a dynamic binary instrumentation framework . ==9214== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al. ==9214== For more details, rerun with: -v ==9214== ==9214== Invalid read of size 4 ==9214== at 0x40CD795: std::string::~string() (in /usr/lib/libstdc++.so.6.0.9 ) ==9214== by 0x8049217: std::pair::~pair() (st l_pair.h:69) ==9214== by 0x8049256: __gnu_cxx::new_allocator >::destroy(std::pair*) (new_allocat or.h:107) ==9214== by 0x80493D8: std::_Rb_tree, std::_Select1st >, comparestrings, std::allocator > >::destroy_node(std::_Rb_tree_node >*) (stl_tree.h:391) ==9214== by 0x8049585: std::_Rb_tree, std::_Select1st >, comparestrings, std::allocator > >::erase(std::_Rb_tree_iterator >) (stl_tree.h:1189) ==9214== by 0x8049653: std::_Rb_tree, std::_Select1st >, comparestrings, std::allocator > >::erase(std::_Rb_tree_iterator >, std::_Rb_tree_iterator >) (stl_tree.h:1281) ==9214== by 0x80496C7: std::_Rb_tree, std::_Select1st >, comparestrings, std::allocator > >::erase(std::string const&) (stl_tree.h:1215) ==9214== by 0x80496E5: std::multimap > >::erase(std::string const&) (stl_multimap.h:421) ==9214== by 0x8048B16: main (test.c:14) ==9214== Address 0xFFFFFFFD is not stack'd, malloc'd or (recently) free'd ==9214== ==9214== Process terminating with default action of signal 11 (SIGSEGV): dumping core ==9214== General Protection Fault ==9214== at 0x40CD795: std::string::~string() (in /usr/lib/libstdc++.so.6.0.9) ==9214== by 0x8049217: std::pair::~pair() (stl_pair.h:69) ==9214== by 0x8049256: __gnu_cxx::new_allocator >::destroy(std::pair*) (new_allocator.h:107) ==9214== by 0x80493D8: std::_Rb_tree, std::_Select1st >, comparestrings, std::allocator > >::destroy_node(std::_Rb_tree_node >*) (stl_tree.h:391) ==9214== by 0x8049585: std::_Rb_tree, std::_Select1st >, comparestrings, std::allocator > >::erase(std::_Rb_tree_iterator >) (stl_tree.h:1189) ==9214== by 0x8049653: std::_Rb_tree, std::_Select1st >, comparestrings, std::allocator > >::erase(std::_Rb_tree_iterator >, std::_Rb_tree_iterator >) (stl_tree.h:1281) ==9214== by 0x80496C7: std::_Rb_tree, std::_Select1st >, comparestrings, std::allocator > >::erase(std::string const&) (stl_tree.h:1215) ==9214== by 0x80496E5: std::multimap > >::erase(std::string const&) (stl_multimap.h:421) ==9214== by 0x8048B16: main (test.c:14) ==9214== ==9214== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 17 from 1) ==9214== malloc/free: in use at exit: 60 bytes in 3 blocks. ==9214== malloc/free: 5 allocs, 2 frees, 94 bytes allocated. ==9214== For counts of detected errors, rerun with: -v ==9214== searching for pointers to 3 not-freed blocks. ==9214== checked 110,708 bytes. ==9214== ==9214== LEAK SUMMARY: ==9214== definitely lost: 0 bytes in 0 blocks. ==9214== possibly lost: 36 bytes in 2 blocks. ==9214== still reachable: 24 bytes in 1 blocks. ==9214== suppressed: 0 bytes in 0 blocks. ==9214== Rerun with --leak-check=full to see details of leaked memory. zsh: segmentation fault (core dumped) valgrind ./a.out etna%