I have a crash in SLL_Next in a setter of an attribute of type vector<pair<int,enum>>
void setA(const vector<pair<int,enum>>& A){_A = A;} // A.size() = 1
class B {
vector<pair<int,enum>> _A {};
public:
void setA(const vector<pair<int,enum>>& A){_A = A;}
};
int main(){
.
.
.
vector<pair<int,enum>> A;
.
.
.
A.push_back(element);
.
.
.
setA(A);// get segfault in SLL_Next
.
.
.
}
Back trace :
Thread 1 "a" received signal SIGSEGV, Segmentation fault.
tcmalloc::SLL_TryPop (rv=<synthetic pointer>, list=0x790f060) at src/linked_list.h:69
69 void *next = SLL_Next(*list);
(gdb) bt
#0 tcmalloc::SLL_TryPop (rv=<synthetic pointer>, list=0x790f060) at src/linked_list.h:69
#1 tcmalloc::ThreadCache::FreeList::TryPop (rv=<synthetic pointer>, this=0x790f060) at src/thread_cache.h:220
#2 tcmalloc::ThreadCache::Allocate (oom_handler=0x7ffff78c5300 <tcmalloc::cpp_throw_oom(unsigned long)>, cl=1, size=8, this=<optimized out>) at src/thread_cache.h:379
#3 malloc_fast_path<tcmalloc::cpp_throw_oom> (size=8) at src/tcmalloc.cc:1874
#4 tc_new (size=8) at src/tcmalloc.cc:1995
#5 0x0000000000506e50 in __gnu_cxx::new_allocator<std::pair<int, enum> >::allocate (this=0x114aedc8, __n=1) at /u/tools/gnu/gcc/os3fp/gcc-6.2.0/include/c++/6.2.0/ext/new_allocator.h:104
#6 0x000000000050334b in std::allocator_traits<std::allocator<std::pair<int, enum> > >::allocate (__a=..., __n=1) at /u/tools/gnu/gcc/os3fp/gcc-6.2.0/include/c++/6.2.0/bits/alloc_traits.h:416
#7 0x00000000004fd3b2 in std::_Vector_base<std::pair<int, enum>, std::allocator<std::pair<int, enum> > >::_M_allocate (this=0x114aedc8, __n=1) at /u/tools/gnu/gcc/os3fp/gcc-6.2.0/include/c++/6.2.0/bits/stl_vector.h:170
#8 0x00000000004f9a92 in std::vector<std::pair<int, enum>, std::allocator<std::pair<int, enum> > >::_M_allocate_and_copy<__gnu_cxx::__normal_iterator<std::pair<int, enum> const*, std::vector<std::pair<int, enum>, std::allocator<std::pair<int, enum> > > > > (this=0x114aedc8, __n=1, __first=..., __last=...)
at /u/tools/gnu/gcc/os3fp/gcc-6.2.0/include/c++/6.2.0/bits/stl_vector.h:1222
#9 0x00000000004f70fc in std::vector<std::pair<int, enum>, std::allocator<std::pair<int, enum> > >::operator= (this=0x114aedc8, __x=...) at /u/tools/gnu/gcc/os3fp/gcc-6.2.0/include/c++/6.2.0/bits/vector.tcc:195
#10 0x00000000004f616e in B::setA (this=0x114aed20, A=...) at ~/WORK/B.h:110
I tried to do the following scenarios:
-
Scenario(1):
- Clear the vector A just before doing
setA(A)
- Replace
_A = A
by_A.reserve(1)
But I got the same segfault.
- Clear the vector A just before doing
Code source became:
class B {
vector<pair<int,enum>> _A {};
public:
void setA(const vector<pair<int,enum>>& A){_A.reserve(1);}
};
int main(){
.
.
.
vector<pair<int,enum>> A;
.
.
.
A.clear();
setA(A);// get the same segfault in SLL_Next
.
.
.
}
-
Scenario(2)
- Replace
void setA(const vector<pair<int,enum>>& A){_A = A}
byvoid setA(const vector<pair<int,enum>>& A){_A.reserve(2)}
, the program pass this segfault and crashes in other different vector with the same segfault.
- Replace
-
Scenario(3)
- If I use a build without tcmalloc, the program will pass successfully.
-
Scenario(4)
- If I change the type of _A from vector to set, the program passes this segfault and crashes with the same segfault in other vectors.
Does anyone have ever faced this kind of issue with using tcmalloc can please advise me on how to solve it?