免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5241 | 回复: 0
打印 上一主题 下一主题

[C++] 求助,std::map和std::string 引发的coredump,不知道啥原因 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-10-22 15:01 |只看该作者 |倒序浏览
本帖最后由 redboy333 于 2012-10-22 15:03 编辑

有段程序跑了大概2小时coredump了。
程序里是用了这样的结构 std::map<std::string,std::string> m_testmap
在一个函数中做了拷贝 m_testmap = testmap

看堆栈是

(gdb) bt
#0  0xffffe410 in __kernel_vsyscall ()
#1  0xf5fb0a30 in raise () from /lib/libc.so.6
#2  0xf5fb2153 in abort () from /lib/libc.so.6
#3  0xf5fe608b in __libc_message () from /lib/libc.so.6
#4  0xf5feba51 in malloc_printerr () from /lib/libc.so.6
#5  0xf5fed224 in free () from /lib/libc.so.6
#6  0xf61ab2b1 in operator delete () from /usr/lib/libstdc++.so.6
#7  0xf618816d in std::string::_Rep::_M_destroy () from /usr/lib/libstdc++.so.6
#8  0xf618acf7 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string ()
   from /usr/lib/libstdc++.so.6
#9  0xf774972a in ~pair (this=0x9f956f2 at /usr/include/c++/4.1.2/bits/stl_pair.h:69
#10 0xf7749775 in __gnu_cxx::new_allocator<std::pair<std::string const, std::string> >::destroy (this=0xad2daf7f, __p=0x9f956f2
    at /usr/include/c++/4.1.2/ext/new_allocator.h:107
#11 0xf7749871 in std::_Rb_tree<std::string, std::pair<std::string const, std::string>, std::_Select1st<std::pair<std::string const, std::string> >, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > >::destroy_node (
    this=0x81da43c, __p=0x9f956f1 at /usr/include/c++/4.1.2/bits/stl_tree.h:391
#12 0xf7749904 in std::_Rb_tree<std::string, std::pair<std::string const, std::string>, std::_Select1st<std::pair<std::string const, std::string> >, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > >::_M_erase (
    this=0x81da43c, __x=0x9f956f1 at /usr/include/c++/4.1.2/bits/stl_tree.h:1266
#13 0xf77499d3 in std::_Rb_tree<std::string, std::pair<std::string const, std::string>, std::_Select1st<std::pair<std::string const, std::string> >, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > >::clear (this=0x81da43c)
    at /usr/include/c++/4.1.2/bits/stl_tree.h:692
#14 0xf6b34783 in std::_Rb_tree<std::string, std::pair<std::string const, std::string>, std::_Select1st<std::pair<std::string const, std::string> >, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > >:perator= (
    this=0x81da43c, __x=@0xad2db0a at /usr/include/c++/4.1.2/bits/stl_tree.h:796
#15 0xf6b34858 in std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<std::string const, std::string> > >:perator= (this=0x81da43c, __x=@0xad2db0a at /usr/include/c++/4.1.2/bits/stl_map.h:227
#16 0xf6b3205a in CmapInfo::setMap (this=0x81d9688, TokenCodeMap=@0xad2db0a


而此时拷贝过去的map的值是

(gdb) pmap tmpMap 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >' 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >'
elem[0].left: $3 = {
  static npos = 4294967295,
  _M_dataplus = {
    <std::allocator<char>> = {
      <__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>},
    members of std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Alloc_hider:
    _M_p = 0x98f74484 "source1"
  }
}
elem[0].right: $4 = {
  static npos = 4294967295,
  _M_dataplus = {
    <std::allocator<char>> = {
      <__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>},
    members of std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Alloc_hider:
    _M_p = 0xf61db5dc ""
  }
}
Map size = 1



想问问各位到底是啥原因?这里的map难道不能这样map<"xxxx","">?这里是空字符串,又不是NULL。搞不懂了?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP