显示调用栈不是出错的代码点,怀疑是内存错误。
Program terminated with signal S, Segmentation fault.
#0 0x00000000010ca227 in tcmalloc::SLL_Next(void*) ()
(gdb) bt
#0 0x00000000010ca227 in tcmalloc::SLL_Next(void*) ()
#1 0x00000000010ca2b8 in tcmalloc::SLL_TryPop(void**, void**) ()
#2 0x00000000010ca715 in tcmalloc::ThreadCache::FreeList::TryPop(void**) ()
#3 0x00000000011ebe6c in tc_newarray ()
这篇文章遇到相同的报错,原因是double free
查找内存错误 - 金庆的专栏 - C++博客
我遇到的原因是,使用了一个map,使用clear清空,多次之后,map的空间便没有释放,所以得使用swap清空
#include <iostream>
#include <map>
#include <malloc.h>
using namespace std;
void func()
{
map<int,string> mp;
int i = 5000000;
while(i--)
mp.insert(make_pair(i,string("hell000o")));
map<int,string>().swap(mp);
}
int main()
{
func();
cout <<"done."<<endl;
malloc_trim(0);
while(1);
}