I used valgrind to check my project written in C++. It told me there was a definitely memory leak in a line with vector assignment.
What valgrind told is
==37533== 514,604 bytes in 124,984 blocks are definitely lost in loss record 369 of 433
==37533== at 0x4C2E0EF: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==37533== by 0x42BB89: __gnu_cxx::new_allocator<int>::allocate(unsigned long, void const*) (new_allocator.h:104)
==37533== by 0x42832B: std::allocator_traits<std::allocator<int> >::allocate(std::allocator<int>&, unsigned long) (alloc_traits.h:491)
==37533== by 0x424565: std::_Vector_base<int, std::allocator<int> >::_M_allocate(unsigned long) (stl_vector.h:170)
==37533== by 0x48B73F: int* std::vector<int, std::allocator<int> >::_M_allocate_and_copy<__gnu_cxx::__normal_iterator<int const*, std::vector<int, std::allocator<int> > > >(unsigned long, __gnu_cxx::__normal_iterator<int const*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int const*, std::vector<int, std::allocator<int> > >) (stl_vector.h:1224)
==37533== by 0x48B2BD: std::vector<int, std::allocator<int> >::operator=(std::vector<int, std::allocator<int> > const&) (vector.tcc:195)
==37533== by 0x603A49: Dict::DATrieT<unsigned short, std::vector<unsigned short, std::allocator<unsigned short> >, std::vector<int, std::allocator<int> > >::buildTrie(std::vector<Dict::DATrieT<unsigned short, std::vector<unsigned short, std::allocator<unsigned short> >, std::vector<int, std::allocator<int> > >::TermCode, std::allocator<Dict::DATrieT<unsigned short, std::vector<unsigned short, std::allocator<unsigned short> >, std::vector<int, std::allocator<int> > >::TermCode> > const&, std::vector<std::vector<Dict::DATrieT<unsigned short, std::vector<unsigned short, std::allocator<unsigned short> >, std::vector<int, std::allocator<int> > >::TrieNode, std::allocator<Dict::DATrieT<unsigned short, std::vector<unsigned short, std::allocator<unsigned short> >, std::vector<int, std::allocator<int> > >::TrieNode> >*, std::allocator<std::vector<Dict::DATrieT<unsigned short, std::vector<unsigned short, std::allocator<unsigned short> >, std::vector<int, std::allocator<int> > >::TrieNode, std::allocator<Dict::DATrieT<unsigned short, std::vector<unsigned short, std::allocator<unsigned short> >, std::vector<int, std::allocator<int> > >::TrieNode> >*> >&) (Datrie.cpp:467)
==37533== by 0x602758: Dict::DATrieT<unsigned short, std::vector<unsigned short, std::allocator<unsigned short> >, std::vector<int, std::allocator<int> > >::build(std::vector<Dict::DATrieT<unsigned short, std::vector<unsigned short, std::allocator<unsigned short> >, std::vector<int, std::allocator<int> > >::TermCode, std::allocator<Dict::DATrieT<unsigned short, std::vector<unsigned short, std::allocator<unsigned short> >, std::vector<int, std::allocator<int> > >::TermCode> > const&) (Datrie.cpp:178)
==37533== by 0x602103: Loader::Trie_Loader::InnerLoad(BaseDict_Collection&) (Trie_Loader.cpp:116)
==37533== by 0x473BA6: deduce::DeduceClassify::Get_Dat_EntityRec() (DeduceClassify.cpp:500)
==37533== by 0x470D7A: deduce::DeduceClassify::init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::shared_ptr<Qp_Dict> const&, Analyse::Analysis*, MINISEARCH::Index*, Normalization::Normalizer*) (DeduceClassify.cpp:53)
==37533== by 0x40E784: queryparser::CQueryParserImpl::Init(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (QueryParserImpl.cpp:120)
The code snippet is
if ((int) (*itVecIter)->code.size() == nLevel + 1)
{
treeNode.bEnd = true;
// NOTE: the memory leak happens at following
treeNode.weight = (*itVecIter)->weight;
itVecIter = vecIter.erase(itVecIter);
}
And the runtime callstack via gdb is
(gdb) bt
#0 Dict::DATrieT<unsigned short, std::vector<unsigned short, std::allocator<unsigned short> >, std::vector<int, std::allocator<int> > >::buildTrie (this=0x7fffffffd8f8, vkey_code=std::vector of length 125163, capacity 131072 = {...},
trie=std::vector of length 31422, capacity 31422 = {...}) at ./tools/Dict/Datrie.cpp:467
#1 0x0000000000602759 in Dict::DATrieT<unsigned short, std::vector<unsigned short, std::allocator<unsigned short> >, std::vector<int, std::allocator<int> > >::build (this=0x7fffffffd8f8, vkey_code=std::vector of length 125163, capacity 131072 = {...})
at ./tools/Dict/Datrie.cpp:178
#2 0x0000000000602104 in Loader::Trie_Loader::InnerLoad (this=0x7fffffffd8e0, dictPtrs=...) at loader//Trie_Loader.cpp:116
#3 0x0000000000473ba7 in deduce::DeduceClassify::Get_Dat_EntityRec (this=0xa2fb28) at Classification/Deduce//DeduceClassify.cpp:500
#4 0x0000000000470d7b in deduce::DeduceClassify::init (this=0xa2fb28, base_Path="..//data/",
qp_dict=std::shared_ptr (count 2, weak 0) 0x1bc14600, tokenizer=0xa2f998, indexer=0xf6efb0, pNormer=0xa2f898)
at Classification/Deduce//DeduceClassify.cpp:53
#5 0x000000000040e785 in queryparser::CQueryParserImpl::Init (this=0xa2f4a0, dataPath="../") at QueryParserImpl.cpp:120
#6 0x000000000043ca92 in main_process::test_main (argc=2, argv=0x7fffffffdd20) at MainProcess.cpp:284
#7 0x00000000006301ae in main (argc=3, argv=0x7fffffffde38) at main.cpp:57
I used template class in Datrie.cpp. And I am not sure why vector assignment with
treeNode.weight = (*itVecIter)->weight;
has memory leaks.
Thanks.
It seems that the assignment operator of treeNode.weight is called, it allocates some memory to use but never de-allocated.
==37533== by 0x48B73F: int* std::vector<int, std::allocator<int> >::_M_allocate_and_copy<__gnu_cxx::__normal_iterator<int const*, std::vector<int, std::allocator<int> > > >(unsigned long, __gnu_cxx::__normal_iterator<int const*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int const*, std::vector<int, std::allocator<int> > >) (stl_vector.h:1224)
==37533== by 0x48B2BD: std::vector<int, std::allocator<int> >::operator=(std::vector<int, std::allocator<int> > const&) (vector.tcc:195)
As #n.m.'s suggestion, I've checked the code whole around. And I think I found the issue. Simplified the class constructor/destructor and manipulation in following:
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
struct leak_struct {
vector<string> array;
int set;
};
int main(){
leak_struct ls;
ls.array.push_back("hello");
ls.array.push_back("world");
memset(&ls, 0, sizeof(ls));
ls.array.push_back("code");
ls.array.push_back("review");
memset(&ls, 0, sizeof(ls));
return 0;
}
The reason it leaks is at the line where memset is called, this call will nullify the vector pointer in struct and makes the new allocated buffer not freed.
Related
When I test run C++ programs with the option -fsanitize=address I see many locations point to an indirect leak. They are all initiated from libasan.so. The exact error shown below. I am not sure that I am responsible for this leak or not. I was able to fixed other direct leaks in my program.
Indirect leak of 16 byte(s) in 1 object(s) allocated from:
#0 0x7f24e2b9c947 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.5+0x10f947)
#1 0x7f24e2517dc8 in __gnu_cxx::new_allocator<std::pair<char, int> >::allocate(unsigned long, void const*) /usr/include/c++/9/ext/new_allocator.h:114
#2 0x7f24e250ed74 in std::allocator_traits<std::allocator<std::pair<char, int> > >::allocate(std::allocator<std::pair<char, int> >&, unsigned long) /usr/include/c++/9/bits/alloc_traits.h:444
#3 0x7f24e24ff853 in std::_Vector_base<std::pair<char, int>, std::allocator<std::pair<char, int> > >::_M_allocate(unsigned long) /usr/include/c++/9/bits/stl_vector.h:343
#4 0x7f24e24e8aa6 in std::_Vector_base<std::pair<char, int>, std::allocator<std::pair<char, int> > >::_M_create_storage(unsigned long) /usr/include/c++/9/bits/stl_vector.h:358
#5 0x7f24e24d8ee8 in std::_Vector_base<std::pair<char, int>, std::allocator<std::pair<char, int> > >::_Vector_base(unsigned long, std::allocator<std::pair<char, int> > const&) /usr/include/c++/9/bits/stl_vector.h:302
#6 0x7f24e24c9782 in std::vector<std::pair<char, int>, std::allocator<std::pair<char, int> > >::vector(std::vector<std::pair<char, int>, std::allocator<std::pair<char, int> > > const&) /usr/include/c++/9/bits/stl_vector.h:552
#7 0x7f24e2579da6 in Hitbrief::Hitbrief(Hitbrief const&) /home/kzhou/coding/molbar/src/readcompass.h:21
#8 0x7f24e2579e5b in std::pair<Hitbrief const, int>::pair<Hitbrief&&, 0ul>(std::tuple<Hitbrief&&>&, std::tuple<>&, std::_Index_tuple<0ul>, std::_Index_tuple<>) /usr/include/c++/9/tuple:1674
#9 0x7f24e25798f0 in std::pair<Hitbrief const, int>::pair<Hitbrief&&>(std::piecewise_construct_t, std::tuple<Hitbrief&&>, std::tuple<>) /usr/include/c++/9/tuple:1663
#10 0x7f24e2578f77 in void __gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<Hitbrief const, int> > >::construct<std::pair<Hitbrief const, int>, std::piecewise_construct_t const&, std::tuple<Hitbrief&&>, std::tuple<> >(std::pair<Hitbrief const, int>*, std::piecewise_construct_t const&, std::tuple<Hitbrief&&>&&, std::tuple<>&&) /usr/include/c++/9/ext/new_allocator.h:147
#11 0x7f24e2577db5 in void std::allocator_traits<std::allocator<std::_Rb_tree_node<std::pair<Hitbrief const, int> > > >::construct<std::pair<Hitbrief const, int>, std::piecewise_construct_t const&, std::tuple<Hitbrief&&>, std::tuple<> >(std::allocator<std::_Rb_tree_node<std::pair<Hitbrief const, int> > >&, std::pair<Hitbrief const, int>*, std::piecewise_construct_t const&, std::tuple<Hitbrief&&>&&, std::tuple<>&&) /usr/include/c++/9/bits/alloc_traits.h:484
#12 0x7f24e2575199 in void std::_Rb_tree<Hitbrief, std::pair<Hitbrief const, int>, std::_Select1st<std::pair<Hitbrief const, int> >, std::less<Hitbrief>, std::allocator<std::pair<Hitbrief const, int> > >::_M_construct_node<std::piecewise_construct_t const&, std::tuple<Hitbrief&&>, std::tuple<> >(std::_Rb_tree_node<std::pair<Hitbrief const, int> >*, std::piecewise_construct_t const&, std::tuple<Hitbrief&&>&&, std::tuple<>&&) /usr/include/c++/9/bits/stl_tree.h:614
#13 0x7f24e25714e9 in std::_Rb_tree_node<std::pair<Hitbrief const, int> >* std::_Rb_tree<Hitbrief, std::pair<Hitbrief const, int>, std::_Select1st<std::pair<Hitbrief const, int> >, std::less<Hitbrief>, std::allocator<std::pair<Hitbrief const, int> > >::_M_create_node<std::piecewise_construct_t const&, std::tuple<Hitbrief&&>, std::tuple<> >(std::piecewise_construct_t const&, std::tuple<Hitbrief&&>&&, std::tuple<>&&) /usr/include/c++/9/bits/stl_tree.h:631
#14 0x7f24e256e7ae in std::_Rb_tree_iterator<std::pair<Hitbrief const, int> > std::_Rb_tree<Hitbrief, std::pair<Hitbrief const, int>, std::_Select1st<std::pair<Hitbrief const, int> >, std::less<Hitbrief>, std::allocator<std::pair<Hitbrief const, int> > >::_M_emplace_hint_unique<std::piecewise_construct_t const&, std::tuple<Hitbrief&&>, std::tuple<> >(std::_Rb_tree_const_iterator<std::pair<Hitbrief const, int> >, std::piecewise_construct_t const&, std::tuple<Hitbrief&&>&&, std::tuple<>&&) /usr/include/c++/9/bits/stl_tree.h:2455
#15 0x7f24e2568f82 in std::map<Hitbrief, int, std::less<Hitbrief>, std::allocator<std::pair<Hitbrief const, int> > >::operator[](Hitbrief&&) /usr/include/c++/9/bits/stl_map.h:518
Even when all leaks are indirect, there is still memory leak in the source code. I was able to track down all leak and eliminate all indirect leaks. Thank for everyone feedback. In the past, eliminating direct leaks removed all the indirect leaks. This is my first experience, I think it is good to share with someone who experienced this situation for the first time.
I'm running a piece of code which allocates memory using std::shared_ptr<>. However, on shutting down the process, GCC ASAN complaints of things like Indirect leak of 91723904 byte(s) in 383 object(s) and there are no direct leaks.
Error -
Indirect leak of 91723904 byte(s) in 383 object(s) allocated from:
#0 0x7f93658497c0 in operator new(unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.5+0xef7c0)
#1 0xc0275b in __gnu_cxx::new_allocator<std::_Sp_counted_ptr_inplace<Horizon::Zone::Game::Map, std::allocator<Horizon::Zone::Game::Map>, (__gnu_cxx::_Lock_policy)2> >::allocate(unsigned long, void const*) /usr/include/c++/8/ext/new_allocator.h:111
#2 0xc01eaf in std::allocator_traits<std::allocator<std::_Sp_counted_ptr_inplace<Horizon::Zone::Game::Map, std::allocator<Horizon::Zone::Game::Map>, (__gnu_cxx::_Lock_policy)2> > >::allocate(std::allocator<std::_Sp_counted_ptr_inplace<Horizon::Zone::Game::Map, std::allocator<Horizon::Zone::Game::Map>, (__gnu_cxx::_Lock_policy)2> >&, unsigned long) /usr/include/c++/8/bits/alloc_traits.h:436
#3 0xc01087 in std::__allocated_ptr<std::allocator<std::_Sp_counted_ptr_inplace<Horizon::Zone::Game::Map, std::allocator<Horizon::Zone::Game::Map>, (__gnu_cxx::_Lock_policy)2> > > std::__allocate_guarded<std::allocator<std::_Sp_counted_ptr_inplace<Horizon::Zone::Game::Map, std::allocator<Horizon::Zone::Game::Map>, (__gnu_cxx::_Lock_policy)2> > >(std::allocator<std::_Sp_counted_ptr_inplace<Horizon::Zone::Game::Map, std::allocator<Horizon::Zone::Game::Map>, (__gnu_cxx::_Lock_policy)2> >&) /usr/include/c++/8/bits/allocated_ptr.h:97
#4 0xc000d3 in std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<Horizon::Zone::Game::Map, std::allocator<Horizon::Zone::Game::Map>, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned short, unsigned short, std::vector<unsigned char, std::allocator<unsigned char> > const&>(std::_Sp_make_shared_tag, Horizon::Zone::Game::Map*, std::allocator<Horizon::Zone::Game::Map> const&, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, unsigned short&&, unsigned short&&, std::vector<unsigned char, std::allocator<unsigned char> > const&) /usr/include/c++/8/bits/shared_ptr_base.h:660
#5 0xbfeda1 in std::__shared_ptr<Horizon::Zone::Game::Map, (__gnu_cxx::_Lock_policy)2>::__shared_ptr<std::allocator<Horizon::Zone::Game::Map>, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned short, unsigned short, std::vector<unsigned char, std::allocator<unsigned char> > const&>(std::_Sp_make_shared_tag, std::allocator<Horizon::Zone::Game::Map> const&, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, unsigned short&&, unsigned short&&, std::vector<unsigned char, std::allocator<unsigned char> > const&) /usr/include/c++/8/bits/shared_ptr_base.h:1328
#6 0xbfd2be in std::shared_ptr<Horizon::Zone::Game::Map>::shared_ptr<std::allocator<Horizon::Zone::Game::Map>, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned short, unsigned short, std::vector<unsigned char, std::allocator<unsigned char> > const&>(std::_Sp_make_shared_tag, std::allocator<Horizon::Zone::Game::Map> const&, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, unsigned short&&, unsigned short&&, std::vector<unsigned char, std::allocator<unsigned char> > const&) (/home/travis/build/horizonxyz/horizon/build/bin/Debug/zone+0xbfd2be)
#7 0xbfb57b in std::shared_ptr<Horizon::Zone::Game::Map> std::allocate_shared<Horizon::Zone::Game::Map, std::allocator<Horizon::Zone::Game::Map>, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned short, unsigned short, std::vector<unsigned char, std::allocator<unsigned char> > const&>(std::allocator<Horizon::Zone::Game::Map> const&, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, unsigned short&&, unsigned short&&, std::vector<unsigned char, std::allocator<unsigned char> > const&) (/home/travis/build/horizonxyz/horizon/build/bin/Debug/zone+0xbfb57b)
#8 0xbfa076 in std::shared_ptr<Horizon::Zone::Game::Map> std::make_shared<Horizon::Zone::Game::Map, std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned short, unsigned short, std::vector<unsigned char, std::allocator<unsigned char> > const&>(std::shared_ptr<Horizon::Zone::Game::MapThreadContainer>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&, unsigned short&&, unsigned short&&, std::vector<unsigned char, std::allocator<unsigned char> > const&) /usr/include/c++/8/bits/shared_ptr.h:723
#9 0xbf4371 in Horizon::Zone::Game::MapManager::LoadMapCache() /home/travis/build/horizonxyz/horizon/src/Server/Zone/Game/Map/MapManager.cpp:107
#10 0xbf06f6 in Horizon::Zone::Game::MapManager::initialize() /home/travis/build/horizonxyz/horizon/src/Server/Zone/Game/Map/MapManager.cpp:49
#11 0x42e82b in Horizon::Zone::ZoneMain::initialize_core() /home/travis/build/horizonxyz/horizon/src/Server/Zone/Zone.cpp:145
#12 0x42f656 in main /home/travis/build/horizonxyz/horizon/src/Server/Zone/Zone.cpp:223
#13 0x7f936372982f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)
As seen above this is allocated using shared_ptr which doesn't require objects to be explicitly freed. But then again, there would need to be an internal call from the STL to delete the object which I think isn't happening as the process ends? Or that GCC isn't able to capture it.
I have this method: (it's supposed to create a inverted list from all the files in the given directory)
class Index{
public:
Index();
void create();
void writeInvertedIndex();
private:
bool isWhiteSpace(const char ch);
std::map<std::string, std::set<int>> invertedIndex;
};
void Index::create(){
std::string datasetPath = "/home/skluzada/Downloads/BI-VWM/Project/dataset/";
std::string filePath, word, text;
std::ifstream infile;
int fileIndex = 0;
std::size_t textLen, i;
DIR * dir;
struct dirent * ent;
if ((dir = opendir (datasetPath.c_str())) != NULL){
while((ent = readdir(dir)) != NULL){
filePath = datasetPath + ent->d_name;
std::cout << filePath << std::endl;
std::ifstream inFile(filePath, std::ios::in);
std::stringstream buffer;
buffer << inFile.rdbuf();
std::string text = buffer.str();
inFile.close();
textLen = text.size();
i = 19;
while (i < textLen){
word = "";
while(isWhiteSpace(text[i])){
i++;
}
while(!isWhiteSpace(text[i])){
word = word + text[i];
i++;
}
invertedIndex[word].insert(fileIndex);
}
fileIndex++;
}
}
}
When I run the program on a small collection of files (around 50Kb of text) it works fine, but when I run it on the real collection (500 files around 1.5Mb in total) it segfaults after processing around 50 files. The output inverted index is about 900Kb.
I suppose that loading the whole file into a string is not an ideal solution (the files are 1-5Kb each) but I'm using a similar approach in other parts of the project and it works fine even on the whole collection.
Could you suggest where is the problem? Or maybe give me some advice on optimization?
The weirdest thing about this is that when I run it with Valgrind it processes the whole collection without segfaulting. This is the Valgrind output:
==9952== Syscall param writev(vector[...]) points to uninitialised byte(s)
==9952== at 0x57F6610: __writev_nocancel (in /usr/lib64/libc-2.25.so)
==9952== by 0x4EEC4B1: std::__basic_file<char>::xsputn_2(char const*, long, char const*, long) (in /usr/lib64/libstdc++.so.6.0.24)
==9952== by 0x4F29BC1: std::basic_filebuf<char, std::char_traits<char> >::xsputn(char const*, long) (in /usr/lib64/libstdc++.so.6.0.24)
==9952== by 0x4F4E063: std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long) (in /usr/lib64/libstdc++.so.6.0.24)
==9952== by 0x401BFC: Index::writeInvertedIndex() (in /home/skluzada/Downloads/BI-VWM/Project/index)
==9952== by 0x4021D0: main (in /home/skluzada/Downloads/BI-VWM/Project/index)
==9952== Address 0x6f929f4 is 84 bytes inside a block of size 2,273 alloc'd
==9952== at 0x4C2E1CA: operator new(unsigned long) (vg_replace_malloc.c:334)
==9952== by 0x4F62144: void std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_construct<char*>(char*, char*, std::forward_iterator_tag) (in /usr/lib64/libstdc++.so.6.0.24)
==9952== by 0x4F6219E: std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (in /usr/lib64/libstdc++.so.6.0.24)
==9952== by 0x404A5F: std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > >::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, 0ul>(std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>&, std::tuple<>&, std::_Index_tuple<0ul>, std::_Index_tuple<>) (in /home/skluzada/Downloads/BI-VWM/Project/index)
==9952== by 0x404782: std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > >::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>(std::piecewise_construct_t, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>, std::tuple<>) (in /home/skluzada/Downloads/BI-VWM/Project/index)
==9952== by 0x40458C: void __gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > > > >::construct<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > >, std::piecewise_construct_t const&, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>, std::tuple<> >(std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > >*, std::piecewise_construct_t const&, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>&&, std::tuple<>&&) (in /home/skluzada/Downloads/BI-VWM/Project/index)
==9952== by 0x404247: void std::allocator_traits<std::allocator<std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > > > > >::construct<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > >, std::piecewise_construct_t const&, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>, std::tuple<> >(std::allocator<std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > > > >&, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > >*, std::piecewise_construct_t const&, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>&&, std::tuple<>&&) (in /home/skluzada/Downloads/BI-VWM/Project/index)
==9952== by 0x403C6C: void std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > >, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > > >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > > > >::_M_construct_node<std::piecewise_construct_t const&, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>, std::tuple<> >(std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > > >*, std::piecewise_construct_t const&, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>&&, std::tuple<>&&) (in /home/skluzada/Downloads/BI-VWM/Project/index)
==9952== by 0x403069: std::_Rb_tree_node<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > > >* std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > >, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > > >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > > > >::_M_create_node<std::piecewise_construct_t const&, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>, std::tuple<> >(std::piecewise_construct_t const&, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>&&, std::tuple<>&&) (in /home/skluzada/Downloads/BI-VWM/Project/index)
==9952== by 0x402C4D: std::_Rb_tree_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > > > std::_Rb_tree<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > >, std::_Select1st<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > > >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > > > >::_M_emplace_hint_unique<std::piecewise_construct_t const&, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>, std::tuple<> >(std::_Rb_tree_const_iterator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > > >, std::piecewise_construct_t const&, std::tuple<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&>&&, std::tuple<>&&) (in /home/skluzada/Downloads/BI-VWM/Project/index)
==9952== by 0x4028A4: std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::set<int, std::less<int>, std::allocator<int> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::set<int, std::less<int>, std::allocator<int> > > > >::operator[](std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (in /home/skluzada/Downloads/BI-VWM/Project/index)
==9952== by 0x40203A: Index::create() (in /home/skluzada/Downloads/BI-VWM/Project/index)
==9952==
==9952== Syscall param writev(vector[...]) points to uninitialised byte(s)
==9952== at 0x57F6610: __writev_nocancel (in /usr/lib64/libc-2.25.so)
==9952== by 0x4EEC4B1: std::__basic_file<char>::xsputn_2(char const*, long, char const*, long) (in /usr/lib64/libstdc++.so.6.0.24)
==9952== by 0x4F29BC1: std::basic_filebuf<char, std::char_traits<char> >::xsputn(char const*, long) (in /usr/lib64/libstdc++.so.6.0.24)
==9952== by 0x4F42581: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const (in /usr/lib64/libstdc++.so.6.0.24)
==9952== by 0x4F4E564: std::ostream& std::ostream::_M_insert<long>(long) (in /usr/lib64/libstdc++.so.6.0.24)
==9952== by 0x401C82: Index::writeInvertedIndex() (in /home/skluzada/Downloads/BI-VWM/Project/index)
==9952== by 0x4021D0: main (in /home/skluzada/Downloads/BI-VWM/Project/index)
==9952== Address 0x5d0f861 is 721 bytes inside a block of size 8,192 alloc'd
==9952== at 0x4C2E8B7: operator new[](unsigned long) (vg_replace_malloc.c:423)
==9952== by 0x4F2AA87: std::basic_filebuf<char, std::char_traits<char> >::_M_allocate_internal_buffer() (in /usr/lib64/libstdc++.so.6.0.24)
==9952== by 0x4F2EC71: std::basic_filebuf<char, std::char_traits<char> >::open(char const*, std::_Ios_Openmode) (in /usr/lib64/libstdc++.so.6.0.24)
==9952== by 0x4F2ED92: std::basic_ofstream<char, std::char_traits<char> >::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode) (in /usr/lib64/libstdc++.so.6.0.24)
==9952== by 0x401B75: Index::writeInvertedIndex() (in /home/skluzada/Downloads/BI-VWM/Project/index)
==9952== by 0x4021D0: main (in /home/skluzada/Downloads/BI-VWM/Project/index)
==9952==
==9952==
==9952== HEAP SUMMARY:
==9952== in use at exit: 32,816 bytes in 1 blocks
==9952== total heap usage: 820,861 allocs, 820,860 frees, 16,188,505,659 bytes allocated
==9952==
==9952== LEAK SUMMARY:
==9952== definitely lost: 32,816 bytes in 1 blocks
==9952== indirectly lost: 0 bytes in 0 blocks
==9952== possibly lost: 0 bytes in 0 blocks
==9952== still reachable: 0 bytes in 0 blocks
==9952== suppressed: 0 bytes in 0 blocks
==9952== Rerun with --leak-check=full to see details of leaked memory
==9952==
==9952== For counts of detected and suppressed errors, rerun with: -v
==9952== Use --track-origins=yes to see where uninitialised values come from
==9952== ERROR SUMMARY: 681764 errors from 10 contexts (suppressed: 0 from 0)
The solution for the asked question is the comment from rafix07:
Why don't you check i < textLen in while(isWhiteSpace(text[i])){i++;} and in next while loop, you probably read data out of range. Change to while (i < textLen && isWhiteSpace[text[i]]){i++;} and do the same in second loop.
This question already has answers here:
Is it smart to replace boost::thread and boost::mutex with c++11 equivalents?
(7 answers)
Closed 9 years ago.
have a code which used to run fine with boost thread under ubuntu. it's basic read only data sharing multithreading. I try to use C++11 instead of boost, very basic transition. the code compiles but have subtle bugs. crashes randomly with C++11 std thread. tried to use valgrind drd, but hard to read the debug info. Any thoughts?
==19608== Conflicting load by thread 3 at 0x00643be8 size 8
==19608== at 0x41CEBA: std::subtract_with_carry_engine<unsigned int, 24ul, 10ul, 24ul>::operator()() (random.tcc:601)
==19608== by 0x41CD6C: double std::generate_canonical<double, 53ul, std::subtract_with_carry_engine<unsigned int, 24ul, 10ul, 24ul> >(std::subtract_with_carry_engine<unsigned int, 24ul, 10ul, 24ul>&) (random.tcc:3475)
==19608== by 0x41CB06: std::__detail::_Adaptor<std::subtract_with_carry_engine<unsigned int, 24ul, 10ul, 24ul>, double>::operator()() (random.h:190)
==19608== by 0x41C877: double std::normal_distribution<double>::operator()<std::subtract_with_carry_engine<unsigned int, 24ul, 10ul, 24ul> >(std::subtract_with_carry_engine<unsigned int, 24ul, 10ul, 24ul>&, std::normal_distribution<double>::param_type const&) (random.tcc:1950)
==19608== by 0x41C688: double std::normal_distribution<double>::operator()<std::subtract_with_carry_engine<unsigned int, 24ul, 10ul, 24ul> >(std::subtract_with_carry_engine<unsigned int, 24ul, 10ul, 24ul>&) (random.h:2196)
==19608== by 0x41C379: nrand(double, double) (NRand.cpp:8)
==19608== by 0x416F78: ClassDef::set_x() (LoanDef.h:407)
==19608== by 0x4168CA: Sim(std::vector<ClassDef, std::allocator<ClassDef> >&, Assumption&, std::unordered_map<std::string, std::vector<double, std::allocator<double> >, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, std::vector<double, std::allocator<double> > > > >&, unsigned int, NextStepCalcML&, std::vector<std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >, std::allocator<std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > > >&, unsigned int, unsigned int) (NewSim.cpp:105)
==19608== by 0x411A09: _ZNSt12_Bind_simpleIFPFvRSt6vectorI7LoanDefSaIS1_EER10AssumptionRSt13unordered_mapISsS0_IdSaIdEESt4hashISsESt8equal_toISsESaISt4pairIKSsS9_EEEjR14NextStepCalcMLRS0_IS0_IS9_SaIS9_EESaISN_EEjjESt17reference_wrapperIS3_EST_IS5_EST_ISI_EjST_ISK_EST_ISP_EjjEE9_M_invokeIILm0ELm1ELm2ELm3ELm4ELm5ELm6ELm7EEEEvSt12_Index_tupleIIXspT_EEE (functional:1732)
==19608== by 0x4116AE: std::_Bind_simple<void (*()(std::reference_wrapper<std::vector<LoanDef, std::allocator<LoanDef> > >, std::reference_wrapper<Assumption>, std::reference_wrapper<std::unordered_map<std::string, std::vector<double, std::allocator<double> >, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, std::vector<double, std::allocator<double> > > > > >, unsigned int, std::reference_wrapper<NextStepCalcML>, std::reference_wrapper<std::vector<std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >, std::allocator<std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > > > >, unsigned int, unsigned int))(std::vector<LoanDef, std::allocator<ClassDef> >&, Assumption&, std::unordered_map<std::string, std::vector<double, std::allocator<double> >, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, std::vector<double, std::allocator<double> > > > >&, unsigned int, NextStep&, std::vector<std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >, std::allocator<std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > > >&, unsigned int, unsigned int)>::operator()() (functional:1720)
==19608== by 0x411647: std::thread::_Impl<std::_Bind_simple<void (*()(std::reference_wrapper<std::vector<ClassDef, std::allocator<ClassDef> > >, std::reference_wrapper<Assumption>, std::reference_wrapper<std::unordered_map<std::string, std::vector<double, std::allocator<double> >, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, std::vector<double, std::allocator<double> > > > > >, unsigned int, std::reference_wrapper<NextStep>, std::reference_wrapper<std::vector<std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >, std::allocator<std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > > > >, unsigned int, unsigned int))(std::vector<LoanDef, std::allocator<LoanDef> >&, Assumption&, std::unordered_map<std::string, std::vector<double, std::allocator<double> >, std::hash<std::string>, std::equal_to<std::string>, std::allocator<std::pair<std::string const, std::vector<double, std::allocator<double> > > > >&, unsigned int, NextStep&, std::vector<std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > >, std::allocator<std::vector<std::vector<double, std::allocator<double> >, std::allocator<std::vector<double, std::allocator<double> > > > > >&, unsigned int, unsigned int)> >::_M_run() (thread:115)
thank you. btw, I tried to use this random head file I wrote, not sure if it's safe under multithread environment. it used to work fine with boost.
myrand.hpp
#ifndef NRAND_H
#define NRAND_H
#include <random>
double nrand(double mean = 0., double sd = 1.);
double urand(double a=0., double b=0.);
#endif
and myrand.cpp
#include "NRand.h"
using namespace std;
double nrand(double mean, double sd) {
static random_device rd;
static subtract_with_carry_engine<unsigned,24,10,24> e(rd());
normal_distribution<> dist(mean, sd);
return dist(e);
}
double urand(double a, double b) {
static random_device rd;
static subtract_with_carry_engine<unsigned,24,10,24> e(rd());
uniform_real_distribution<> dist(a, b);
return dist(e);
}
many thanks.
IMHO, your code is not threadsafe and hence should not work correctly under C++11. I think the problem is that the static variables rd and e are global variables but not protected (by mutex), so concurrent calls will race.
Presumably, you can make this code threadsafe by making those variables thread_local, but I have no experience.
As stated in the title, I have a seg fault occurring and I have no idea why. The closest maybe-related issue that I could dig up is this. My system specs are as follows:
RHELv5u8
icpc version 12.1.0 (gcc version 4.1.2 compatibility)
arch = x86_64
And the problem doesn't seem to occur when compiling with g++.
I have isolated the problem to a relatively small snippet of code:
#include <iostream>
#include <cstdio>
#include <vector>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/vector.hpp>
#include <string>
#include <fstream>
using namespace std;
int main()
{
cout << "Testing ... ";
vector<int> outVect(10);
// Save the data
std::ofstream outputFile_("archive.txt");
outputFile_ << std::scientific;
boost::archive::text_oarchive textOutArchive_(outputFile_);
cout << "chk1" << endl;
textOutArchive_ & BOOST_SERIALIZATION_NVP(outVect);
cout << "chk2" << endl;
return 0;
}
And I am compiling thusly:
icpc -g -static -openmp standalone.cc -o minimal -lboost_serialization ; ./minimal
Any ideas?
Valgrind gives me the following:
Testing ... chk1
==24519== Jump to the invalid address stated on the next line
==24519== at 0x0: ???
==24519== by 0x403100: boost::serialization::detail::extended_type_info_typeid_1<std::vector<int, std::allocator<int> > const>::get_instance() (extended_type_info_typeid.hpp:96)
==24519== by 0x4027C0: boost::archive::detail::oserializer<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::oserializer() (oserializer.hpp:106)
==24519== by 0x402934: boost::archive::detail::oserializer<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::instantiate() (oserializer.hpp:135)
==24519== by 0x402764: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::save_standard::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:264)
==24519== by 0x4027AA: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::save_conditional::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:273)
==24519== by 0x40274A: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:322)
==24519== by 0x40364E: void boost::archive::save<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:536)
==24519== by 0x401A85: void boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<std::vector<int, std::allocator<int> > const>(std::vector<int, std::allocator<int> > const&, int) (basic_text_oarchive.hpp:78)
==24519== by 0x4021D5: boost::archive::text_oarchive& boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<< <std::vector<int, std::allocator<int> > const>(std::vector<int, std::allocator<int> > const&) (interface_oarchive.hpp:78)
==24519== by 0x402E49: void boost::serialization::nvp<std::vector<int, std::allocator<int> > >::save<boost::archive::text_oarchive>(boost::archive::text_oarchive&, unsigned int) const (nvp.hpp:77)
==24519== by 0x402C9E: void boost::serialization::access::member_save<boost::archive::text_oarchive, boost::serialization::nvp<std::vector<int, std::allocator<int> > > const>(boost::archive::text_oarchive&, boost::serialization::nvp<std::vector<int, std::allocator<int> > > const&, unsigned int) (access.hpp:93)
==24519== Address 0x0 is not stack'd, malloc'd or (recently) free'd
==24519==
==24519==
==24519== Process terminating with default action of signal 11 (SIGSEGV)
==24519== Bad permissions for mapped region at address 0x0
==24519== at 0x0: ???
==24519== by 0x403100: boost::serialization::detail::extended_type_info_typeid_1<std::vector<int, std::allocator<int> > const>::get_instance() (extended_type_info_typeid.hpp:96)
==24519== by 0x4027C0: boost::archive::detail::oserializer<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::oserializer() (oserializer.hpp:106)
==24519== by 0x402934: boost::archive::detail::oserializer<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::instantiate() (oserializer.hpp:135)
==24519== by 0x402764: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::save_standard::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:264)
==24519== by 0x4027AA: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::save_conditional::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:273)
==24519== by 0x40274A: boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >::invoke(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:322)
==24519== by 0x40364E: void boost::archive::save<boost::archive::text_oarchive, std::vector<int, std::allocator<int> > >(boost::archive::text_oarchive&, std::vector<int, std::allocator<int> > const&) (oserializer.hpp:536)
==24519== by 0x401A85: void boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::save_override<std::vector<int, std::allocator<int> > const>(std::vector<int, std::allocator<int> > const&, int) (basic_text_oarchive.hpp:78)
==24519== by 0x4021D5: boost::archive::text_oarchive& boost::archive::detail::interface_oarchive<boost::archive::text_oarchive>::operator<< <std::vector<int, std::allocator<int> > const>(std::vector<int, std::allocator<int> > const&) (interface_oarchive.hpp:78)
==24519== by 0x402E49: void boost::serialization::nvp<std::vector<int, std::allocator<int> > >::save<boost::archive::text_oarchive>(boost::archive::text_oarchive&, unsigned int) const (nvp.hpp:77)
==24519== by 0x402C9E: void boost::serialization::access::member_save<boost::archive::text_oarchive, boost::serialization::nvp<std::vector<int, std::allocator<int> > > const>(boost::archive::text_oarchive&, boost::serialization::nvp<std::vector<int, std::allocator<int> > > const&, unsigned int) (access.hpp:93)
==24519==
Long comment:
Statically linking with pthreads (used by the OpenMP run-time) never works correctly unless the whole libpthreads.a archive is linked in. To work around it you should append -Wl,--whole-archive -lpthreads -Wl,--no-whole-archive to the compilation options.
But then, I see no parallel regions in your code so activating OpenMP is redundant. Besides, it looks more like RTTI is failing with icpc as the error occurs in something, called from inside extended_type_info_typeid.hpp.