应用程序退出时的SegFault

时间:2016-08-05 11:13:34

标签: c++ valgrind

我在工作中使用的应用程序之一遇到了一个奇怪而恼人的问题。应用程序是用C ++编写的,当应用程序终止时(主函数返回或exit被调用),它会因分段错误而崩溃。分段错误似乎是由basic_string类析构函数中的双重释放指针引起的。我无法添加源代码,但我可以说应用程序非常简单,我不是直接在我的代码中使用任何指针。该应用程序只是从库中调用函数。

Valgrid确定了以下问题:

==5402== Invalid read of size 4
==5402==    at 0x549F05F: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() (atomicity.h:49)
==5402==    by 0x41D1BA4: ??? (in ../Functions.so)
==5402==    by 0x436D873: ??? (in ../Functions.so)
==5402==    by 0x967674: _dl_fini (in /lib/ld-2.12.so)
==5402==    by 0x9A7EAE: exit (in /lib/libc-2.12.so)
==5402==    by 0x810F8C2: main (Checker.C:146)
==5402==  Address 0x55ec808 is 8 bytes inside a block of size 15 free'd
==5402==    at 0x4007895: operator delete(void*) (vg_replace_malloc.c:480)
==5402==    by 0x549EF67: std::string::_Rep::_M_destroy(std::allocator<char> const&) (new_allocator.h:110)
==5402==    by 0x810F8C2: main (Checker.C:146)
==5402==
==5402== Invalid free() / delete / delete[] / realloc()
==5402==    at 0x4007895: operator delete(void*) (vg_replace_malloc.c:480)
==5402==    by 0x549EF67: std::string::_Rep::_M_destroy(std::allocator<char> const&) (new_allocator.h:110)
==5402==    by 0x41D1BA4: ??? (in ..../Functions.so)
==5402==    by 0x436D873: ??? (in .../Functions.so)
==5402==    by 0x967674: _dl_fini (in /lib/ld-2.12.so)
==5402==    by 0x9A7EAE: exit (in /lib/libc-2.12.so)
==5402==    by 0x810F8C2: main (Checker.C:146)
==5402==  Address 0x55ec800 is 0 bytes inside a block of size 15 free'd
==5402==    at 0x4007895: operator delete(void*) (vg_replace_malloc.c:480)
==5402==    by 0x549EF67: std::string::_Rep::_M_destroy(std::allocator<char> const&) (new_allocator.h:110)
==5402==    by 0x810F8C2: main (Checker.C:146)
==5402==

应用程序链接到共享库和静态库。 Function.so是一个共享库,可能包含一些静态代码。此问题与链接阶段有关,因为根据库与我的可执行文件链接的顺序,应用程序可能不会崩溃。

我真的很难解决这个问题,任何想法可能是这个问题的根本原因?有任何建议如何继续调查此问题?

1 个答案:

答案 0 :(得分:0)

此问题的根本原因是代码中的某个错误。这个bug可以是任何东西。野生指针取消引用,运行数组的末尾,或任何数量的其他无数种类的错误。 C ++代码中的错误并不一定意味着应用程序会立即崩溃。应用程序可以继续执行,但在稍后尝试访问由该错误导致的损坏内存时崩溃。

您的代码中某处可能存在导致内存损坏的错误,这会在应用程序终止时触发此崩溃。你需要找到它并修复它。欢迎来到C ++。

相关问题