C++ 程序退出时_tcf_0处的分段错误

C++ 程序退出时_tcf_0处的分段错误,c++,segmentation-fault,exit-code,C++,Segmentation Fault,Exit Code,当程序退出时,将提供以下信息: *** glibc detected *** double free or corruption (!prev): 0x09a8fcb8 *** 它似乎在一个物体上有双重自由。然后我使用gdb调试coredump文件。以下是bt结果(未发布更多跟踪): 然后valgrind结果显示字符串被两个不同的.so文件(libkmm.so.2.0.0和libpv.so.2.0.0)删除。 详细信息(某些行被屏蔽): ==28125==Invalid free()/del

当程序退出时,将提供以下信息:

*** glibc detected *** double free or corruption (!prev): 0x09a8fcb8 ***
它似乎在一个物体上有双重自由。然后我使用gdb调试coredump文件。以下是bt结果(未发布更多跟踪):


然后valgrind结果显示字符串被两个不同的.so文件(libkmm.so.2.0.0和libpv.so.2.0.0)删除。 详细信息(某些行被屏蔽):

==28125==Invalid free()/delete/delete[]
==28125==at 0x400588F:运算符删除(void*)(vg_replace_malloc.c:387)
==28125==by 0x446548C:std::string::_Rep::_M_destroy(std::allocator const&)(new_allocator.h:97)
==28125==0x55FA7E7:uu tcf_u0(in/home/alan_tao/vm/test/lib/libkmm.so.2.0.0)
==28125==0x55D5A6:退出(在/lib/tls/libc-2.3.4.so中)
==28125==by 0x42B10D9:stop_sim()(在/home/alan_tao/vm/test/lib/libcomm.so.2.0.0中)
==28125==0x807C83A:func_on_退出(int)(in/home/alan_tao/vm/test/bin/engine)
==28125==0x55A917:???(in/lib/tls/libc-2.3.4.so)
...
==28125==地址0x4a484d0是大小为525 free'd的块中的0字节
==28125==at 0x400588F:运算符删除(void*)(vg_replace_malloc.c:387)
==28125==by 0x446548C:std::string::_Rep::_M_destroy(std::allocator const&)new_allocator.h:97)
==28125==0x650C0B7:u tcf_0(in/home/alan_tao/vm/test/lib/libpv.so.2.0.0)
==28125==0x55D5A6:退出(在/lib/tls/libc-2.3.4.so中)
==28125==by 0x42B10D9:stop_sim()(在/home/alan_tao/vm/test/lib/libcomm.so.2.0.0中)
==28125==0x807C83A:func_on_退出(int)(in/home/alan_tao/vm/test/bin/engine)
==28125==0x55A917:???(in/lib/tls/libc-2.3.4.so)


valgrind结果显示一个字符串被删除两次。但我不知道是哪一个。谁知道删除哪个字符串会导致错误以及如何修复它?谢谢

PS:该程序在linux 2.6.9下运行。gcc版本为4.2.2。使用动态链接库

新更新: 使用gdb列出错误库文件,命令“l\uu tcf\u 0”向我显示以下代码:

inline std::vector<const char*>& get_phase_name_vec(){
  static std::vector<const char*> phase_name_vec(END_RESP+1, (const char*)NULL);
  return phase_name_vec;
}
inline std::vector&get\u phase\u name\u vec(){
静态std::向量相位名称向量(END_RESP+1,(const char*)NULL);
返回阶段\名称\向量;
}

这来自OSCI TLM头文件。而上述库必须包含它们。它位于一个单独的名称空间“tlm”中。有没有办法解决这个错误?

问题解决了。libkmm.so.2.0.0的源文件和tlm头文件中存在全局变量名冲突


似乎“l\uu tcf\u 0”没有显示正确的变量。感谢Alex、maverik、IulianŞerbănoiu和其他阅读此问题的人。

查看应用程序的内存以查看此字符串是什么,它可能仍然存在,没有完全覆盖。实验将日志添加到你的应用程序。有创意。你能给我们展示一个你认为应用程序崩溃的代码吗?谢谢!我试过这个。0x9a8fcb8处的指针值为0。有许多静态字符串存储在不同的类中。单个共享常量字符串,如:const::std::string ARR_I2S[33]={“0”、“1”、“2”、“3”、“4”、“5”、“6”、“7”、“8”、“9”、“10”、“11”、“12”、“13”、“14”、“15”、“16”、“17”、“18”、“19”、“20”、“21”、“22”、“23”、“24”、“25”、“26”、“27”、“28”、“29”、“30”、“31”、};你能在问题重现的地方贴一个最小的样本吗?假设代码是什么样子是没有意义的。
==28125== Invalid free() / delete / delete[]
==28125==    at 0x400588F: operator delete(void*) (vg_replace_malloc.c:387)
==28125==    by 0x446548C: std::string::_Rep::_M_destroy(std::allocator<char> const&) (new_allocator.h:97)
==28125==    by 0x55FA7E7: __tcf_0 (in /home/alan_tao/vm/test/lib/libkmm.so.2.0.0)
==28125==    by 0x55D5A6: exit (in /lib/tls/libc-2.3.4.so)
==28125==    by 0x42B10D9: stop_sim() (in /home/alan_tao/vm/test/lib/libcomm.so.2.0.0)
==28125==    by 0x807C83A: func_on_exit(int) (in /home/alan_tao/vm/test/bin/engine)
==28125==    by 0x55A917: ??? (in /lib/tls/libc-2.3.4.so)
...
==28125==  Address 0x4a484d0 is 0 bytes inside a block of size 525 free'd
==28125==    at 0x400588F: operator delete(void*) (vg_replace_malloc.c:387)
==28125==    by 0x446548C: std::string::_Rep::_M_destroy(std::allocator<char> const&) new_allocator.h:97)
==28125==    by 0x650C0B7: __tcf_0 (in /home/alan_tao/vm/test/lib/libpv.so.2.0.0)
==28125==    by 0x55D5A6: exit (in /lib/tls/libc-2.3.4.so)
==28125==    by 0x42B10D9: stop_sim() (in /home/alan_tao/vm/test/lib/libcomm.so.2.0.0)
==28125==    by 0x807C83A: func_on_exit(int) (in /home/alan_tao/vm/test/bin/engine)
==28125==    by 0x55A917: ??? (in /lib/tls/libc-2.3.4.so)
inline std::vector<const char*>& get_phase_name_vec(){
  static std::vector<const char*> phase_name_vec(END_RESP+1, (const char*)NULL);
  return phase_name_vec;
}